LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass a pointer to an array of structs to a DLL function?

Hi Folks,

Sorry to bother you with this, I couldn't find anything online to answer this question. I am running Labview 6.0 on a Win2k machine. I am using a .dll that has a struct defined in it:

struct {
uns16 s1;
uns16 s2;
uns16 sbin;
uns16 p1;
uns16 p2;
uns16 pbin;
} rgn_struct;

And a function prototype that has an array of these structs as an argument and looks like:

void thisfunc(..., rgn_struct *rgn_array, ...);

I have been unable to create a happy Call Library Function Node that passes something that works. I have tried making arrays, and arrays of clusters, but haven't quite gotten the right combination yet. If you could point me to a tutorial with this s
tyle of function call in it, or just jot an email with the right format, I would appreciate it greatly. In the meantime, I will continue to fight with it and repost if I get it to work.

Thanks for your help!
Sam
0 Kudos
Message 1 of 22
(5,430 Views)
I don't see how you can get there from here.
The trouble is that C thinks of an array of THINGS as a simple pointer to a THING (which happens to be followed by another thing, which happens to be followed by another thing, etc.)

In LabVIEW, true arrays are different, because they are dynamic. They are passed by HANDLES (pointer to a pointer), and the first U32 in the data space is the number of items in that dimension (first TWO U32s if it's a 2-D array, etc.).

For a 1-D array then, the 0th data structure is at h** + 4 bytes.

If you have to have a true variable-sized array in the LabVIEW side, you're hosed, unless you can modify the DLL code.

If you can establish a maximum limit, though, you can get by with a fake array - Create a cluster li
ke this:

U16 s1;
U16 s2;
U16 sbin;
U16 p1;
U16 p2;
U16 pbin;
... in that order. then put several of those clusters in a second cluster (label them 0,1,2,3...).

If you pass THAT to a dll, the dll sees a pointer to the first data item of the first structure, exactly as it expects. Immediately after that is the 2nd element, just as it expects.

Again, that only works if you can define some reasonable maximum, and build a cluster to contain that many. You will pass that much data every time, even if not all of it is used.

Hope that helps.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 22
(5,430 Views)
Dear CMB,

Thanks - I am lucky, my array of structs is finite length: 1. So I make a cluster as you say, and then I embed it in another cluster so that I have a cluster of clusters. Now how do I pass this to the Call Library Function Node? When I flatten it using cluster to array, I just get (as expected) an array of clusters, which is probably not right and doesn't work anyway. All I want to do is hand it a pointer to the start of my cluster of clusters.

Thanks for the quick reply - a bit more help and I should be good to go.

sam
0 Kudos
Message 3 of 22
(5,430 Views)

When I flatten it using cluster to array,
--- Why do you do that? The whole point of my message was to AVOID using arrays. You DON'T WANT an array (at least a LabVIEW array) involved.

in the CONFIGURE dialog for the CALL LIBRARY function:

1... Set the PARAMETER control to whichever argument you are dealing with (maybe you have more than one arg).
2... Set the TYPE to ADAPT TO TYPE (then the library call will accept anything).
3... It doesn't matter what you set the DATA FORMAT control to - you're not passing handles anymore.
4... Wire the cluster you've built to the appropriate argument input on the CALL LIBRARY node.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 22
(5,430 Views)
SJW wrote:

> Thanks - I am lucky, my array of structs is finite length: 1.
> So I make a cluster as you say, and then I embed it in another
> cluster so that I have a cluster of clusters. Now how do I pass this
> to the Call Library Function Node? When I flatten it using cluster to
> array, I just get (as expected) an array of clusters, which is
> probably not right and doesn't work anyway. All I want to do is hand
> it a pointer to the start of my cluster of clusters.

Well since you need only one element, you can actually simplify it. Just
create the single cluster. No need to put another cluster around it.
Tell the Call Library Node to use "Adapt To Type" for that parameter and
then just wire the clu
ster wire to the left side of that parameter. Voila!

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 22
(5,430 Views)
Rolf is correct - I missed the fact that you said your array needs to be of length 1. I read that "1" as a listing of the steps you were going to dsecribe, didn't notice there was no "2".

In that case, a single-level cluster will suffice, though the original plan will do no harm.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 22
(5,430 Views)
I thought I answered already, it seems not -- You guys are awesome - it works just as it should. I left my cluster as a double level, just to conform with the "spirit" of the DLL declaration, if not the letter of it. Thanks for all your help - I hope I can return the favor someday.

sam
0 Kudos
Message 7 of 22
(5,430 Views)
I hope I can return the favor someday.
You can.
There are bound to be questions on this forum you can answer.
Answer them.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 8 of 22
(5,430 Views)
"... return the favor ..."

In the meanwhile, you could give Coastal... some stars.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 22
(5,430 Views)
done
0 Kudos
Message 10 of 22
(5,430 Views)