LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

allocate memory and call dll function which writes to the pointer

Solved!
Go to solution

Hi!

 

I have a DLL wich has a function like the following example, wich i need to call from labview. In C I need to allocate some memory for the data and of course the struct. I add the pointer and the lengh of the data to the stuct and call the function with the struct. The function itself inserts some values to the stuct and to allocated memory. Has someone a working solution how this can be done with Labview?

 

typedef struct Thestruct
{
 UINT16 val1;
 UINT8 val2;
 UINT8 val3;
 UINT16 dataLength;
 UINT8 *data;
} T_Thestruct;

 

MY_API Status MY_API_CALL udaReceive(Handle handle, T_Thestruct *args);

 

I tried in labview (see picture), but I only got values inside the struct as well as the error 1097, the reserved memory inclues the same values as before.

0 Kudos
Message 1 of 3
(2,475 Views)
Solution
Accepted by topic author Tobias_BSH

OK, I found the soluton to my own Problem. The alignment on the struct must be corrected in Labview. There must be a 2Bytes dummy value between dataLength and the pointer. Smiley Frustrated

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

@Tobias_BSH wrote:

OK, I found the soluton to my own Problem. The alignment on the struct must be corrected in Labview. There must be a 2Bytes dummy value between dataLength and the pointer. Smiley Frustrated


And please not that your solution only works in LabVIEW 32 bit. In LabVIEW 64 Bit your DLL has to be 64 bit compiled as well in order to be loadable and the pointer then is a 64 bit integer and is usually aligned to 64 bit addresses too. In this particular case since the pointer is already aligned to a multiple of 64 bit (when the additional 2 alignment bytes are added) you won't have to modify the alignment for the 64 bit case, but you have to define a different cluster with the 64 bit integer for the pointer anyhow.

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