From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW crahses after passing structure pointers to DLL from LabVIEW

Hi,

 

I have a DLL which returns a table (array) of 33 values after passing its arguments correctly.

I need to pass two structure pointers as arguments to an API of this DLL from LabVIEW.

For this, I have used call library function node and the structure arguments are created with Type "Adapt to Type" as there is no direct cluster passing facility in drop down menu of "Type".

Whenever I run my VI, each time LabVIEW crashes directly.

I am unable to find out the exception because of which LabVIEW crashes immediately.

Please find attached herewith a .zip file which contains -

1. My VI

2. DLL which is being called

3. Screenshots of the documentation of API, (there are total 3..one for API documentation and 2 for its arguments that need to be passed)

4. One screenshot of C example for your reference

 

Kindly provide me with the solution at the earliest as I am stuck and can't proceed with my further development.

 

Best Regards,

Snehal 

0 Kudos
Message 1 of 2
(2,507 Views)

@SuLAB wrote:

Hi,

 

I have a DLL which returns a table (array) of 33 values after passing its arguments correctly.

I need to pass two structure pointers as arguments to an API of this DLL from LabVIEW.

For this, I have used call library function node and the structure arguments are created with Type "Adapt to Type" as there is no direct cluster passing facility in drop down menu of "Type".

Whenever I run my VI, each time LabVIEW crashes directly.

I am unable to find out the exception because of which LabVIEW crashes immediately.

Please find attached herewith a .zip file which contains -

1. My VI

2. DLL which is being called

3. Screenshots of the documentation of API, (there are total 3..one for API documentation and 2 for its arguments that need to be passed)

4. One screenshot of C example for your reference

 

Kindly provide me with the solution at the earliest as I am stuck and can't proceed with my further development.

 

Best Regards,

Snehal 


Well fixed size arrays in C are really inlined inside a structure. That means that your 25 elements of dSpoolpositions and dLvdtRawVal elements are directly placed inside the structure as if you had placed 25 double values each in there. This can be simulated by LabVEW by placing 25 double control elements each inside the cluster or you could define another cluster with 25 elements and place it twice in the cluster. Note that if the C struct would contain an array pointer this would be still not the same as a LabVIEW array as LabVIEW uses handles for its arrays not pointers. 

 

As it is labVIEW passes a structure with two array pointers (consuming 4 bytes each in the cluster) to the DLL where as the DLL expects 2 * 25 doubles * 8 bytes instead, so the DLL when trying to update the structure catastrophallically tries to write into memory that is way off from the buffer allocated for the structure by LabVIEW and therefore destroying some other data in LabVIEW, which explains the fatal crash.

 

The other parameter I can't say for sure. You mentionthat it contains 33 elements so it is likely also a fixed size array, but without seeing the definition of  LVDT_TABLE_T itself I can't say if that is true.

 

Generally it is safe to say that placing LabVIEW arrays and strings into a cluster and passing them to a DLL is ALWAYS wrong unless the DLL was specifically written to be used with LabVIEW (and then the C programmer who did that DLL better understands how he needs to treat those handles properly in C).

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