LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library, DLL, input an array of char

I am trying to figure out how to configure a Call Library calling a function that has a array of file name paths.  It's a old DLL but I'm force to use it.  I've already successfully used Call Library to run other functions except this one since I don't know how to configure it correctly.


What I'm calling is:

ERRORTYPE LoadFiles(File_Array *files, int size, char *Buffer, char *outputfile)

 

Note File_Array is:

struct File_Array
{

      char FileName[256};

};

 

Note ERRORTYPE is an enum for error code response ie 0 is OK, 1 is Load Error.

 

In the Call Library, I know the size is an numeric, buffer is a string, and outputfile is a string..

I can't figure out what Call Library parameter settings I need to use for File_Array.  Note that File_Array would be list/array of file names paths.  Can someone help me figure out how to configure the Call Library parameter for the "File_Array" section of the input parameters for my DLL?   Thanks for the help.

0 Kudos
Message 1 of 4
(2,440 Views)

Do you know what size refers to here? The LabVIEW equivalent of your struct File_Array is a cluster of 256 U8 elements. So, you need to pass at least one of those, by reference. It seems likely, though, that what's actually intended is for you to pass an array of such clusters, where size is likely the number of them. Do you have any more information about exactly how this function is supposed to be called?

0 Kudos
Message 2 of 4
(2,429 Views)

Size refers to # of files inputed into the File_Array.  (don't ask me why the original programmer did that.. I think it's redundant since you can see the array size already)

 

Typically the DLL is called in a executable build using C++.  The original programmer made the DLL and the executable separate for some reason.  I believe they wanted to make a version that was a GUI interface and another build being a command line input prompt, all built in C++.  The GUI interface works with the DLL fine, but that interface has major issues.  We want to move it to LabVIEW, but since I don't have the "magic sauce" in all the formatting of it communicating to another device, I have to resort to hack coding.  

 

I could modify the original DLL, but it's certified release which costs a lot of money.  I was hoping I could just tap into the the DLL via Call Library.  So far I could do all the other functions perfectly using Call Library, but I have no idea how to deal with array of chars as an input..

 

I did do a beta test of making a duplicate function in the DLL but made it input only a single file (char *), and it worked as expected.  But as mentioned that would cost the company thousands of dollars to certify the software vs just reusing the DLL.

 

I didn't know if this would work but within the Call Library Function, for the parameters, I was thinking of using Type "Adapt to Type" and Data format to be "Array Data Pointer"..  
Edit: I just tried the Adapt to Type and it didn't seem to work.

0 Kudos
Message 3 of 4
(2,405 Views)

@Rhidium wrote:

Size refers to # of files inputed into the File_Array.  (don't ask me why the original programmer did that.. I think it's redundant since you can see the array size already)

You can in LabVIEW but C arrays are very different. In C the caller and the callee both need to know how large an array is in order to not overrun memory but an array does not contain an intrinsic size anywhere, so you have to pass that to the callee in a separate parameter (or the callee documents that it always expects a very specific number of array elements).

 

Typically the DLL is called in a executable build using C++.  The original programmer made the DLL and the executable separate for some reason.  I believe they wanted to make a version that was a GUI interface and another build being a command line input prompt, all built in C++.  The GUI interface works with the DLL fine, but that interface has major issues.  We want to move it to LabVIEW, but since I don't have the "magic sauce" in all the formatting of it communicating to another device, I have to resort to hack coding.  

 

I could modify the original DLL, but it's certified release which costs a lot of money.  I was hoping I could just tap into the the DLL via Call Library.  So far I could do all the other functions perfectly using Call Library, but I have no idea how to deal with array of chars as an input..

 

I did do a beta test of making a duplicate function in the DLL but made it input only a single file (char *), and it worked as expected.  But as mentioned that would cost the company thousands of dollars to certify the software vs just reusing the DLL.

 

I didn't know if this would work but within the Call Library Function, for the parameters, I was thinking of using Type "Adapt to Type" and Data format to be "Array Data Pointer"..  
Edit: I just tried the Adapt to Type and it didn't seem to work.


No it won't! The array element is 256 bytes embedded in the structure and each array element appended to the previous so you really get a buffer of "256 * size" bytes.

 

So you need to create an array of "size * 256" bytes unsigned 8 bit integers and copy the "size" string elements into that byte array at the offsets that are a multiple of 256. Then configure the parameter as an array of unsigned 8 bit integers and passed as Array Pointer.

Alternatively you can append to each filename "256 - filename_length" \0 characters, concatenate them all together into one single large string and then pass that as C string pointer to the parameter. This last method will only work if you do not wire the right terminal of this parameter back out as the Call Library Node would terminate the string at the first NULL byte (or "\0" character) when returning the string buffer to the diagram.

 

This is the principle for the first method:

 

Array of filenames.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,399 Views)