Converting a LabVIEW String to a Character Array and Passing Its Pointer to a Call Library Function Node

Updated Nov 24, 2020



  • LabVIEW

I want to use LabVIEW's Call Library Function Node to access a DLL function. I need to pass a string to the function, but its prototype requires a parameter defined as a pointer to a character array. How do I create the array of characters from the string and pass its pointer to the DLL?

LabVIEW strings are not null-terminated C-style strings. LabVIEW strings are similar to Pascal-style strings in the sense that the first four bytes contain the length of the string.

There are two ways to take a LabVIEW string and pass it to a DLL that is expecting a char * (pointer to character array). The most common method is to define the function parameter as a CStr. When you place a Call Library Function Node on the block diagram, double-click it to specify the prototype of the function you want to call. Here you will specify the parameter to be type String and the format to be C String Pointer. Notice how the prototype displays the data type CStr. This data type is equivalent to char *.

If you are working with string-based instrument control, it may be easier to pass an array of 8-bit integers than C strings because of the possibility of NULL values in the string. When you place a Call Library Function Node, double-click it to specify the prototype of the function you want to call. The key here is to specify the parameter type as Array and its data type as Unsigned 8-bit Integer. The dimension of the array is 1 and the format is Array Data Pointer. In LabVIEW you must convert the string to a byte array using the String to Byte

For complete documentation on how to use LabVIEW code with other programming languages in LabVIEW 7.1 or earlier, refer to the Using External Code in LabVIEW 2010 Help. In LabVIEW 8.0 or later, refer to the Fundamentals»Calling Code Written in Text-Based Programming Languages book in the current LabVIEW Help for more information.