LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a library that expects array of pointers as argument (unsigned char **)

Hi,
 
   I am trying to use a library function (DLL) from LabVIEW 8.0.  The argument is a char ** where essentially the function is expecting an array of character pointers.  Basically this a 2D array of strings (null terminated char strings).  Each line is a null terminated string.  From C I would create a 1 D char * array and load the array with the starting address for each row in the 2D array.  Any suggestions on how to do this would be appreciated.  I do need to use the DLL and keep it in it's current format.
 
 
Thanks,
 
BC
0 Kudos
Message 1 of 4
(2,967 Views)


@rvc wrote:
Hi,
 
   I am trying to use a library function (DLL) from LabVIEW 8.0.  The argument is a char ** where essentially the function is expecting an array of character pointers.  Basically this a 2D array of strings (null terminated char strings).  Each line is a null terminated string.  From C I would create a 1 D char * array and load the array with the starting address for each row in the 2D array.  Any suggestions on how to do this would be appreciated.  I do need to use the DLL and keep it in it's current format.

While it is theoretically possible to write a VI that does this all in LabVIEW it is an extremely tedious operation with virtually dozens of Call Library Node calls to create that string array and half a dozen other Call Library Node calls to tear it down afterwards. This is both tiresome, tricky and very vulnerable to bugs.

Your only realistic bet is to write a wrapper C function that takes a normal LabVIEW string array and converts it into the C string array as required by your function. You can add that fucntion to your DLL as an extra export and if that is no option you should create a separate DLL. Creating a separate DLL also has an advantage if you end up using any LabVIEW manager calls. This keeps the dependencies on the LabVIEW manager separated from your main DLL and in such a way will allow you to keep using that main DLL in other environments than LabVIEW.

Rolf Kalbermatter

Message Edited by rolfk on 02-24-2006 11:52 AM

Rolf Kalbermatter
My Blog
Message 2 of 4
(2,963 Views)
Hi,


I usually use GetProcessHeap, HeapAlloc and lstrcpyA (in a loop, so \00 gets copied too) to get a valid pointer to a string. Then afterwards, HeapFree.


If you do this once, with a string, and get one pointer, you can easily build an array of pointers to characters (each pointer is the previous+1).


There are some exported functions in LabVIEW.exe that will do the same, but I always forget how to use them.


Regards,


Wiebe.



"rvc" <x@no.email> wrote in message news:1140721840348-329430@exchange.ni.com...
Hi,
&nbsp;
&nbsp;&nbsp; I am trying to use a library function (DLL) from LabVIEW 8.0.&nbsp; The argument is a char ** where essentially the function is expecting an array of character pointers.&nbsp; Basically this a 2D array of strings (null terminated char strings).&nbsp; Each line is a null terminated string.&nbsp; From C I would create a 1 D char * array and load the array with the starting address for each row in the 2D array.&nbsp; Any suggestions on how to do this would be appreciated.&nbsp; I do need to use the DLL and keep it in it's current format.
&nbsp;
&nbsp;
Thanks,
&nbsp;
BC
Message 3 of 4
(2,957 Views)
Hi,
 
    My thanks to those who replied.  My solution to this problem was the following. 
 
  1. Convert each string in the array of strings to a null terminated byte array.
  2. Write a DLL function that expects a unsigned char * as a parameter and returns the array address as a long value.  (No systems calls necessary).
  3. Pass each char array into the DLL function and create an array of the returned addresses.
  4. Pass these into the function expecting the char **. 

This method seems to work just fine.  The two prior posts were helpful in coming up with this method.

Thanks,

 

BC

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