LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NO access to certain cells when passing 2D array to DLL

I am trying to feed a 2D array (image reading) to a DLL, but it always gives a 1097 error. I debugged the original C++ code. It narrows down to the point that some pixels cannot be read. So I write a simple C code to reproduce the issue. 

 

As you can see from the following screenshot, this C code simply returns the number indexed by 'index'. When fed from Labview to the DLL, I chose to feed a 2D array as 'Array Data Pointer'. Then I put it in a for loop to read through the entire array. The returned array showed that the cells after 75th row cannot be read with a 1097 error. But why? What did I do wrong? 

C_Array_Test Array Data Pointer.jpg

 

C_Array_Test DLL Setup.jpg

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

Hi,

Is it possible that when you index past the 75th row, it's past the end of the supplied data?  Your DLL expects the input to be an array of Doubles (8 bytes), but you're passing in a table of ? I32?  If I32 then you're pre-allocated array is half as big as needed.  Try chainging the type of the initialize-array to U64 and see what happens...

 

Cheers!

0 Kudos
Message 2 of 5
(2,466 Views)

That was my first guess too. But it is not the reason. You can tell that there is not type conversion into the DLL. I specifically made them both the same type, the U32.

0 Kudos
Message 3 of 5
(2,447 Views)

Yes, initialize-array initializes a table of I32, and the type in the CLF matches, but the DLL is still indexing into (what it thinks is) an array of Double - see the function syntax the C source-code: "(double *x",...).

If you simply change the initialize-array type to U64, it will allocate enough space.  It's not even necessary to correct for type conversion - you're still passing a pointer, the DLL will be happy. Smiley Wink

0 Kudos
Message 4 of 5
(2,434 Views)

Probably better to change the DLL from "double" to "int" to match the data that you're actually passing to it. A double is 64 bits. An int is 32 bits. The array indexing operator in C knows the size of the array data type and uses that to compute the offset from the start of the array. When you pass data that's of a different type, the array indexing doesn't work properly. As 550nm explained, the data types need to match between the C function and the LabVIEW data.

0 Kudos
Message 5 of 5
(2,425 Views)