10-27-2010 12:12 PM - edited 10-27-2010 12:17 PM
Hi all.
Well, I have spent several days totally stuck with this problem. I hope you can help me...
It deals with passing a data structure from LabView to C++ via dll.
Imagine you have the following data structure in LabView:
It consists of the following:
I use a Call Library Function Node, and select "Adapt to Type". In this node, if a select "Create C file..." I get the data structure description to use in C/C++ and the function prototype:
typedef struct { int32_t num; LStrHandle name; } TD4; typedef struct { int32_t dimSize; TD4 Cluster2[1]; } TD3; typedef TD3 **TD3Hdl; typedef struct { double height; TD3Hdl Array2; } TD2; typedef struct { int32_t dimSize; TD2 Cluster1[1]; } TD1; typedef TD1 **TD1Hdl; void funcName(TD1Hdl LabViewData); void funcName(TD1Hdl LabViewData) { /* Insert code here */ }
Well, now, in my C++ code, I want to create a variable of a similar datatype to the entry datatype. For example, I create another data structure, similar to the previous, but adding several fields with C++ classes:
typedef struct { int32_t num; LStrHandle name; } TD8; typedef struct { int32_t dimSize; TD8 Cluster2[1]; } TD7; typedef TD7 **TD7Hdl; typedef struct { double height; TD7Hdl Array2; class1* object1; class2 object2; } TD6; typedef struct { int32t dimSize; TD6 Cluster1[1]; } TD5;
Now, I need to create a variable of datatype TD5, called DllData and copy to it all the information that stores the variable LabViewData.
When I try this, I get exception errors. Maybe I have to initialize DllData, and I'm missing something.
Could you please help me?
Thanks in advance.
Regards,
Francisco
10-27-2010 01:32 PM
Can you post your LabVIEW code, preferably just a small VI that shows how you are using the Call Library Node, and the C function you're calling? I'm having trouble understanding what you are trying to do. Passing variable-length data (arrays and strings) between LabVIEW and C is difficult because you need to get the memory allocation right. You need to pass a fully-allocated array into the call library node: the array must contain the right number of elements and the strings (in each array element) must have enough characters to store the data you want to get. If you to allocate the array elements inside the C function instead you should use the LabVIEW memory manager functions as documented in the help for creating a code interface node (the same functions apply to DLLs), and this is hard to get right.
Have you considered writing several C functions, each of which returns one small portion of the structure, then using bundle and build array in LabVIEW to assemble the data?