Jump to content

calling dll which returns a struct


Recommended Posts

Hi all,

I searched high and low in NI's website for solutions for calling a DLL which returns a struct (the DLL is for third party SMU cards). I wonder if it is alright to ask here for some guidelines. I have never used C before and has relied on NI LabVIEW and NI's cards for most of the work done. Appreciate the help.

Here is the a snippet of the header file for the DLL. As shown below the struct contains a float,float and short

typedef struct SMUmeasurement

{

float Voltage;

float Current;

short MeasurementStatus;

} SMUmeasurement;

and here is the function that returns the struct value:

SMUmeasurement WINAPI MeasureAvrgVandI_SMU_DM200(short DeviceID, short SampleCount);

When I used the LabVIEW 8.5 dll import wizard, I found out that it only returns a unsigned integer instead of a nice cluster. Please see attached image.

Thanks for the guidance,

Regards,

Philip

Link to comment

QUOTE (GorionQuest @ Mar 21 2008, 12:02 AM)

Hi all,

I searched high and low in NI's website for solutions for calling a DLL which returns a struct (the DLL is for third party SMU cards). I wonder if it is alright to ask here for some guidelines. I have never used C before and has relied on NI LabVIEW and NI's cards for most of the work done. Appreciate the help.

Here is the a snippet of the header file for the DLL. As shown below the struct contains a float,float and short

typedef struct SMUmeasurement

{

float Voltage;

float Current;

short MeasurementStatus;

} SMUmeasurement;

and here is the function that returns the struct value:

SMUmeasurement WINAPI MeasureAvrgVandI_SMU_DM200(short DeviceID, short SampleCount);

When I used the LabVIEW 8.5 dll import wizard, I found out that it only returns a unsigned integer instead of a nice cluster. Please see attached image.

Thanks for the guidance,

Regards,

Philip

The only way to deal with that in LabVIEW besides writing a wrapper DLL, is to treat it as a uInt32 as far as the Call Library Node is concerned. Then using the MoveBlock() internal call in LabVIEW (search for that name here or on the NI forums) or some other OS API memory copy function, copying the contents from the uInt32 which is now treated as the pointer into a LabVIEW Cluster of compatible layout.

Rolf Kalbermatter

Link to comment

QUOTE (rolfk @ Mar 21 2008, 06:57 PM)

The only way to deal with that in LabVIEW besides writing a wrapper DLL, is to treat it as a uInt32 as far as the Call Library Node is concerned. Then using the MoveBlock() internal call in LabVIEW (search for that name here or on the NI forums) or some other OS API memory copy function, copying the contents from the uInt32 which is now treated as the pointer into a LabVIEW Cluster of compatible layout.

Rolf Kalbermatter

Hi rolfk,

Thanks for the answer, I was tempted to write a wrapper for the DLL since it was recommended in most NI forums but I do not have the source code for the dll in C/C++. But I will try the MoveBlock() if it could solve this problem. Thanks for the guidance! I have been using LabVIEW too extensively, guess I need to learn C programming to make full use of the external code call to maximise LabVIEW. Again thanks for the information.

Philip

Link to comment

Hi guys,

Basically here is my code after the advice. Please let me know if you think I have done it wrong. Much appreciate the advice. I have not tested it on the hardware as I need it to be hooked up properly to test it. I used the MoveBlock() code from LabVIEW to get the data from the pointer passed by the uint32 into the first parameter of the MoveBlock() and wired a cluster constant with 2 SGL and one I16 to reflect the struct which is float, float and short. The size of the struct should be 12 bytes. Thanks for any feedback.

Philip

Link to comment

QUOTE (GorionQuest @ Mar 23 2008, 06:11 AM)

and wired a cluster constant with 2 SGL and one I16 to reflect the struct which is float, float and short. The size of the struct should be 12 bytes. Thanks for any feedback.

Make that 10 bytes: float: 4 byte, float: 4 byte, short: 2 byte, together: 10 bytes. Otherwise you are corrupting memory during the MoveBlock call.

Rolf Kalbermatter

Link to comment

QUOTE (rolfk @ Mar 24 2008, 09:57 PM)

Make that 10 bytes: float: 4 byte, float: 4 byte, short: 2 byte, together: 10 bytes. Otherwise you are corrupting memory during the MoveBlock call.

Rolf Kalbermatter

Many thanks for the correction. Please let me know if you happen to be in Penang, Malaysia. I would be happy to give you a tour.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.