LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble accessing a returned struct from a DLL function

Solved!
Go to solution

I realize this is a recurrent theme on the forums, but I haven't been able to find a thread that has successfully helped me fix my problem, so here I am posting.

 

I am working with a third party dll to pull x,y,z data from a device. I am encountering trouble when trying to use the following C function (via Call Library Node):

 

int ArmGetTipPosition ( length_3D *pPosition );

 

where:

 

typedef float   length;

 

 

typedef struct
{
length  x;
length  y;
length  z;
} length_3D;

 

 

----

 

1) The obvious solution I've found on this forum is to create a cluster of 3 SGL values and pass a pointer to the cluster into the function. In the Call Library Node, I configure the parameter to type: "Adapt to Type" and Data Format: "Handles by Value". While I don't get an error when I do this, I get a cluster full of 0's coming out. In fact, the function return value indicates that the call was successful.

 

2) Another option is to import the dll into labview and have it create custom VIs and a custom length_3D type (which turns out to be exactly the same as doing option 1 above). I've done this, and I get the same result as above.

 

3) Lastly, it seems most folks recommend to write a wrapper C function to spit out the data in a type that LV can directly work with. I am hoping to not go this option, as it is outside my area of expertise.

 

I'm hoping my primitive understanding of either C or LV is to blame here, can someone confirm this?

 

Thanks a bunch,

Ray

0 Kudos
Message 1 of 5
(2,408 Views)
Solution
Accepted by topic author rillian

Is it possible that your DLL really is returning a cluster full of 0's?  Perhaps you need to call some other function in the DLL first to get something initialized?  If the cluster you pass into the Call Library Node contains non-zero values, does it affect the output?

Message 2 of 5
(2,376 Views)

I suppose it is possible that the DLL is returning a cluster of 0's, but I find that very unlikely. It seems more likely that I am not handling the returned struct properly, or not passing in the proper cluster to begin with. If I pass in non-zero values, I still get 0's coming out.

 

Also, I make a call to several functions to initialize the arm before I request the x,y,z coordinates. Thanks for your help.

0 Kudos
Message 3 of 5
(2,369 Views)

 


@rillian wrote:

I suppose it is possible that the DLL is returning a cluster of 0's, but I find that very unlikely. It seems more likely that I am not handling the returned struct properly, or not passing in the proper cluster to begin with. If I pass in non-zero values, I still get 0's coming out.


Since you're dealing with pointers, this is a good indication that the DLL is in fact updating the values in the cluster, and putting in 0s.  You could try passing the cluster as an array of three elements and see if you get different results, but it sounds to me like it's the DLL that's at fault and not your LabVIEW code.

 

Message 4 of 5
(2,365 Views)

Problem solved! Turns out I was missing a call to one more initialization function before the arm could give me x,y,z coordinates. Thank you nathand for your prompt response, you were dead on.

0 Kudos
Message 5 of 5
(2,357 Views)