LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass array of cluster to DLL

I am making a VI that has an array of clusters (see attachment). I need to pass this array to a DLL that will process it and return the result (array of same size). As an example I created a vi that has two arrays that are made up of a cluster containing 5 fileds - four strings and one integer. A C routine gets the array and chages field number 4 to "TESTING" (real app is much more involving, but this will do for now). The program keeps blowing up, so I need help.

Struct definition:

typedef

struct{
  
char name[256];
  
char title;
  
char units;
  
char status;
  
int precision;
} PARAMETER_INFO_ARRAY;

extern

"C" _declspec (dllexport) void addVariables(PARAMETER_INFO_ARRAY *input[], int numArgs)
{
...............
...............
}

Any ideas?

0 Kudos
Message 1 of 2
(2,907 Views)
Yes, it is going to blow up because the structure "does not mean what you think it means".
 
The fundamental problem here is that LabVIEW data types are not C data types. The Call Library Node can handle mapping simple types, but C is such an open style language that it is almost impossible to automatically create the right conversion 100% of the time. Also, C has no concept of metadata, so there isn't anything that the DLL can tell us to help guide our conversion (compared to what we can do with ActiveX and .NET, which do provide metadata).
 
There are two approaches I would recommend here, but both involve creating a wrapper DLL to do the data conversion for you (or adding new methods to the existing DLL if you have the source).
 
The first one is to create a simple export such as
 
extern "C" _declspec (dllexport) void addOneVariable(CStr name, char title, char units, char status, long precision)
{
...............
...............
}
 
Then call it once for each variable you want to add.
 
Second option, if you want to instead pass all of them at once, you are going to need to switch to a CIN instead of a Call Library Node and use the exported LabVIEW C routines to convert the LV data pointers into your structure. In this specific case it doesn't look like it would be that hard, but you'll need to read the section in the manual on CINs.
0 Kudos
Message 2 of 2
(2,890 Views)