LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView Structure Initialisation under LabWindows/CVI ?

Hello,

I build a DLL under LabView and I want to call a function of this DLL under LabWindows/CVI.
A parameter of the function is a structure:
typedef struct
{
int32 dimSize;
LStrHandle String[1];
} TD6;
typedef TD6 **TD6Hdl;

My paremeter is:
TD6Hdl sLVRegisterNames;

I want to initialise this parameter with two elements:
"SPI_name_0" and "SPI_name_1".

I know how to initialise the LStrHandle but how to initialise a such structure?
Everything I tried make the DLL crashes!!!! The problem seems to be be with the structure initialisation...


Regards, Pascal.
0 Kudos
Message 1 of 3
(3,107 Views)
What types are SPI_name_0 and SPI_name_0?
Are they int32 ?

Your string you probably initilize by

sLVRegisterNames.String="";

Is it the following that is failing?

sLVRegisterNames.dimSize = SPI_name_0

If it is, then maybe you defined SPI_name_0 using an enum?

And the compiler may be allocating a differnt type other than int32 to your enums.

The error you are probably getting is some sort memory access error ?

Hope this helps

Regards

Chris
0 Kudos
Message 2 of 3
(3,107 Views)
The LStrHandle data type is composed of two parts:
4 byte containing the length of the string
Array of characters representing the string with no terminating character. You need to allocate a new string handle for each element you wish to add to the array, not only initialize the array handle itself.

Once you make sure you've initialized the string structure correctly using the labview memory manager functions ( using malloc() wont work) , you could try something like this.

strncpy((*yourLVStringHandle)->str, "mystring", strlen("mystring") );

(*yourLVStringHandle)->len = strlen("mystring");

Refer to the using External Code in LV more information on the memory manager functions.

So create your string one at a time, and then add it to your array structure. Watch out for funky pointer math, since the array handle is a pointer to a pointer to a structure, and your LV string handle is also a pointer to a pointer to a struct.

I hope this helps.

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 3 of 3
(3,107 Views)