LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Representing char** in LabVIEW

If a function in a C library requires one of the input to be char** (ie:    int main(int argc, char** argv)  ), what would be the correct way to send in that input within LabVIEW? I know that in C char** argv is equivalent to char*[array_size]   (ie an array of Strings)
0 Kudos
Message 1 of 9
(5,539 Views)

You've answered the question yourself..  😉

You can send an array of strings.  You may have to format it appropriately, which you can do using the string manipulation tools.

JLV

 

0 Kudos
Message 2 of 9
(5,534 Views)
To create an array of string, I used a couple of String constants and send them into a build cluster array. Is that the correct way to do it?

When I went to call the DLL, the data type for the parameter only allowed a CString pointer, pascal string pointer, string handle, and string handle pointer. Which param type is the correct one?
0 Kudos
Message 3 of 9
(5,529 Views)
No...  to build simply an array of strings, go to your front panel, right click->Array and Cluster->Array, which will give you an empty array container, then drop a string control/indicator into the array container, and it should snap to the size of the control/indicator.  You can then manipulate that array from the block diagram (initialize, insert, delete, etc.)

To get a multidimensional array, simply right click on the index control of the array (on the FP) and click "Add dimension"...  I doubt this is suited to your needs at the moment, but it might be useful to know...
0 Kudos
Message 4 of 9
(5,515 Views)
hmmm I tried that, but it will not connect to the Call Library Function node that requires a char** input.
0 Kudos
Message 5 of 9
(5,505 Views)
I guess the real question is in the Call Library Function Node, how do you force the input param to be a char** ?
0 Kudos
Message 6 of 9
(5,503 Views)

The double star means a pointer to a pointer (a double pointer), right?  I believe that pointers to pointers are really not something that LabVIEW can deal with.  You will need to write a wrapper in C and call it from LabVIEW.  In the wrapper, you will need to dereference at least one level of pointer.

I hope that this helps,

Bob

0 Kudos
Message 7 of 9
(5,494 Views)

elliot.ee wrote: I guess the real question is in the Call Library Function Node, how do you force the input param to be a char** ?

Well you can't directly and doing it all on LabVIEW level is a very messy and involved process just not worth the trouble. The extra difficulty here is that char **var really also can mean char *var[n] or even char var[m][n] which are equivalent as far as the C compiler itself is concerned but quite a bit different as far as memory management and access constraints are concerned.

The "simple" solution (and believe me it is a lot simpler than trying to do it otherewise on the LabVIEW diagram level) is to write a wrapper function along these lines:

struct {

  int32 len;

  LStrHandle str[0];

} LStrArr, **LStrArrHdl;

MgErr CallStrArrFromLabVIEWArr(LStrArrHdl arr) {

  int i, len;

  LStrHandle h;

  char **p = DSNewPClr(((*arr)->len + 1) * sizeof(char *)));

  if (!p) return mFullErr;

  for (i = 0; i < (*arr)->len; i++)

  {

    h = (*arr)->str[i];

    len = LStrLen(*h);

    p[i] = DSNewPClr(len + 1) * sizeof(char)));

    if (!p) goto exit;

    MoveBlock(LStrBuf(*h), p[i], len);

  }

  CallToStrArr(p);

exit:

  for (; i; i--)

  {

     if (p[i]) DSDisposePtr(p[i]);

     DSDisposePtr(p);

  }

  return noErr;

}

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 9
(5,331 Views)
A char type in C is equivalent to a U8 in Labview.  In C, char is really the ASCII code of the character.  In Labview, convert the character to ASCII by using the Type Cast function.
 
Now for a string of characters.  If the length of the string is variable, you must use the wrapper that Rolf mentioned.
 
However, if the length is always known, you can convert the string into an array of U8 ASCII bytes.  Then convert the array into a cluster using the Array to Cluster function.  Right click on the Array to Cluster funtion and set the cluster length to the length of the array.  Send this cluster into the Call Library Node.  When setting up the parameters for the Call Library, this parameter must be set to Adapt to Type, and the data format must be Pointer to Handles.  It works fine for me.
 
OOOPS Smiley Surprised  Just read about the **, pointer to a pointer.  Well I never tackled this one.  Don't think my trick will work.  You could try bundling the cluster into another cluster.

Message Edited by tbob on 12-13-2006 09:01 AM

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 9
(5,310 Views)