LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pass cluster to C dll, having issues

I have a dll that, when called, will fill a provided struct {uint32, uint32, uint32, char stuff[64]} with information.  The API says I should pass it a pointer, and it will return the filled struct.

I'm new at this level of complex interaction with dll's.  My first thought (based on a suggestion from a coworker) was to make a cluster of controls and wire it into the dll, and make a second cluster of indicators and wire that into the dll's output, and just hope it worked.  (It didn't.)

My second attempt was to make a pointer, bundle it into the input cluster, and pass that to the dll.  (didn't work either.  I tried this because I found a similar project on NI's website: https://forums.ni.com/t5/Developer-Center-Resources/Calling-C-C-DLLs-Containing-Simple-and-Complex-D... where the example program did this.  (The example program shows up on my machine with an error in the step where the pointer is wired into the bundle-by-name function, in fact.))

 

I think the right way to do this is to make a pointer to a chunk of allocated memory large enough to fit the struct, pass that to the dll, then...?  Wire the output to moveblock and try to parse that for my data?

 

I've looked at a LOT of examples of doing related things, and I see a lot of ways other people have done things that look similar to what I'm doing, and there's a lot of differences among their implementations, and none of the versions I've tried have returned anything but garbage (because, I suspect, I'm getting the contents of some random chunk of memory.)

Any suggestions would be welcome.

0 Kudos
Message 1 of 3
(2,479 Views)

The right way to do this is to create a cluster which contains 3 * uint32 value, and another cluster inside this cluster that contains 64 * uint8. Then configure the Call Library Node parameter to Adapt to Type, and wire this cluster to it. On return unbundle the cluster and convert the cluster of uint8 to an array of uint8 (Cluster to Array Node), then if stuff is really meant to be a string (in C there is no syntactical difference between an array of char values and a string) search for a NULL int8 in the array and resize the array to the length of that index, then convert it to a String, otherwise if it is not a string you are already done with it. Bundle everything into a new cluster with the desired elements.

 

The "char stuff[64]" is a fixed size array. The C compiler will always inline this into the struct (cluster) making the memory buffer in total 3 * 4 + 64 bytes long.

If you place a LabVIEW string in the cluster, what is passed to the DLL is something entirely different, since LabVIEW stores strings and arrays in handles, which a C DLL only can deal with if it was specifically written with LabVIEW datatypes in mind. 

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 3
(2,441 Views)

Thank you!  I will give that a try.

0 Kudos
Message 3 of 3
(2,423 Views)