LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with C library: Pointers and Struct

Hello!

I'm currently trying to import a C library into Labview but I cannot figure out how to do so on a specific function.
It looks like this : int myFunc(char* arg1, struct myStruct** arg2).
In the call dll function node window, the wizard suggests to convert the output to double, the char* stays a char*, but it converts my struct** into a void*. How can I manage to declare a variable to properly use my function ? Is it even possible ? I declare a struct* when using this library in C.
Sorry if this is a repost but I could not find a topic related to my problem. I hope my issue is clear enough.
Thanks in advance!

0 Kudos
Message 1 of 3
(904 Views)

The way I always do this is design the interface with the call library node first (using the Adapt to Type) then have it generate the code for the header (right click the library node and click Create C File). So for your struct, design a similar cluster in Labview then adapt to type it into the call library node. See the help for information on the Data Format but I think handles by value should be ok.

 

Then in C you probably will need to write some interface code because the data layout may not be exactly the same (or you need to copy into the Labview memory).

 

I recommend you always pre-allocate memory in Labview first, where applicable. For example, if you want to pass an array of U8s to your Labview code from the C, first preallocate the U8 array in Labview (initalize array) then pass it into the C function then copy the data into the array. There are ways to make Labview aware pointers in C but I always find them to be more trouble than they are worth.

0 Kudos
Message 2 of 3
(870 Views)

The fact that the myStruct is passed as a reference to the pointer leaves myriads of interpretations open. Does the DLL function allocate and handle this struct and pass a pointer to it back? If so you have a problem as that is not how you can work easily in LabVIEW. If not, why in hell has the programmer decided to pass this as a reference to the pointer????

 

And once that is answered there is another question: What does this struct contain? Only scalars and fixed size arrays, or also pointers? All of these can make this a fairly easy exercise or a hell of a job to solve without writing an intermediate shared library (or if you control the source code of that DLL, adapt it to work with more LabVIEW friendly parameters!!)

Rolf Kalbermatter
Averna BV
0 Kudos
Message 3 of 3
(864 Views)