LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an Array of String from Labview to a CVI dll

Hi,

I can't find the way to pass an array of strings from Labview to a dll with a prototype as shown below:
void WriteRegisters (unsigned int uiArraySize, unsigned int uiArrayOfValues[], char *ArrayOfNames[])
the 2 last parameters are arrays, and uiArraySize is their size.

From Labview, I insert in a diagram the "call library function" object, link to the dll, but it doesn't recognize the parameters types of this function.
As written in the development library, I force the 2nd parameter to "Array" of "unsigned 32-bits integer", its OK (I can get the values in the C Code)
I try to do the same with the 3rd parameter, it doesn't work (I thougth it was possible to force it a an "Array" of "unsigned 8-bit
s integer" . So I test the option "Adapt to type" and "handle by value" as it was described in a NI sample, but when I debug in CVI (in the function body), I can't retrieve the parameters passed from Labview.

I can modify the C function prototype, but only with basic types, as char ** for example (no CStr or LSTrHandle...)

If someone can solve the problem...
Kindest,
Zib
0 Kudos
Message 1 of 2
(3,218 Views)
> I can't find the way to pass an array of strings from Labview to a dll
> with a prototype as shown below:
> void WriteRegisters (unsigned int uiArraySize, unsigned int
> uiArrayOfValues[], char *ArrayOfNames[])
> the 2 last parameters are arrays, and uiArraySize is their size.
>

There are several problems here due to how generic C treats strings.
From the prototype the C DLL could either expect a read-only array of
char* pointers to inspect or copy from, and the assumption would be that
the strings would be NULL terminated. This works OK for western
nonbinary strings.

A second interpretation could be that the DLL expects an array of
malloced pointer blocks containing strings, and that the DLL can realloc
them if it chooses to, placing
the pointer back into the array.

Because of the difficulty in specifying this info in a dialog, and in a
C header file, the LV DLL node will not support this datatype the way
you are looking for.

You have several choices. OLE Automation/COM/ActiveX have more specific
types with less ambiguity about who allocates, reallocates, and
deallocates the memory. If you can put an ActiveX interface over your
DLL, then you will find that the interface is much easier to hook into LV.

Another choice is to put the strings together into one string and pass a
second array of sizes or offsets in the the string where to locate the
info. This requires a little bit of programming on both sides, but it
shouldn't be too bad as long as there aren't tons of strings and the
strings aren't huge.

Greg McKaskle
Message 2 of 2
(3,218 Views)