LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a structure by reference to DLL

Solved!
Go to solution

Hello!

I'm using LV 2018 (x64) and I'm trying to call DLL function.

How do you send the reference to the structure to the DLL instead of pointer to the structure?

This is the function description and example:

Annotation 2021-12-21 092558.pngAnnotation 2021-12-21 092610.png

This is the LV program and cluster (structure) declaration.

strucl113_0-1640076141038.png

strucl113_1-1640076202030.png

strucl113_2-1640076282215.png

 

 

The problem is, when I try to execute this VI, I get a memory management error and the LV crashes. How do you send the reference to the structure to the DLL instead of pointer to the structure?

I have checked that the cluster data is in the same order as the structure in DLL. The data types are all correct (signed I32). Is it possible that I have mismatching memory alignment between LV and DLL?. How to check this? The DLL is precompiled and I cannot edit it.

 

Any help would be appreciated.

Rok

 

 

0 Kudos
Message 1 of 3
(953 Views)
Solution
Accepted by strucl113

Your problem is not to pass a reference to the structure instead of a pointer. Those two are in fact synonymous to each other, at least in terms of C programming which the DLL calls are, so there is no difference between the two. If you would talk about C++ there are semantic differences but technically in terms of what the compiler generates it is still the same.

 

Your problem is that your structure/cluster should contain a fixed size array. A C compiler does not include that in a structure as a pointer and even if it did, a LabVIEW array is NOT a C array pointer.

 

Luckily for you there is a pretty simple solution for you. Replace the array in your cluster with another cluster that contains 32 Int32 numbers. Now the LabVIEW cluster is equivalent in memory layout to the C structure that function expects. 

Rolf Kalbermatter
My Blog
Message 2 of 3
(913 Views)

Thank you for your explanation and solution! 

 

I have changed my program according to you, and it works now!

 

Thank you very much

Rok

0 Kudos
Message 3 of 3
(904 Views)