Creating and Calling LabVIEW DLLs With Various Data Types From LabWindows/CVI

Updated Oct 7, 2020

Environment

Software

  • LabVIEW
  • LabWindows/CVI

This document explains how to use several different data types in the creation of DLLs in LabVIEW 6i and how to call them from LabWindows/CVI. Some of the sections contain links to examples. The process of creating DLLs with LabVIEW 6i or calling the DLL from LabWindows/CVI is not shown in detail in this document. For more details, please see the links at the bottom of the page.

Accessing LabVIEW 6i Numbers from LabWindows/CVI

There are several different combinations for passing numbers in a LabVIEW function. LabWindows/CVI can access these methods similarly. The following Function Prototype has three numeric inputs and three numeric outputs. In/Out 1 are 32-bit integers, In/Out 2 are double-precision floating point numbers, and In/Out 3 are unsigned 8-bit integers. In1 and In3 are set up to be passed by value, while In2 is set up to be passed as a pointer to value. The three outputs must be passed as pointers to values.

Note: You can use either Standard or C Calling Conventions if you are calling the DLLs that use numbers from LabWindows/CVI.


To call the Numtest function, simply add the header (.h) file and library (.lib) file to your project. Also include the header file in your source code (#include <numtest.h>).

The variables can be created in the code in the following manner:

uInt8 in3 = 5;
float64 in2 =3.68 ;
int32 in1 = -100;
uInt8 out3;
float64 out2;
int32 out1;

The actual call to the function looks like this:

Numtest(in3,&in2,in1,&out3,&out2,&out1);

Notice that In2 and the three outputs need to take the address of their values since they were defined as being passed as pointers to values when the DLL was created.
 

Accessing LabVIEW 6i Booleans from LabWindows/CVI

When creating DLLs in LabVIEW 6i, you can only pass Boolean parameters as pointers to values. The following Function Prototype has one Boolean input and one Boolean output.

Note: You can use either Standard or C Calling Conventions if you are calling the DLLs that use Booleans from LabWindows/CVI.


To call the Booltest function, simply add the header (.h) file and library (.lib) file to your project. Also include the header file in your source code (#include <booltest.h>).

The Boolean variables need to be created in the code in the following manner:

LVBoolean in;
LVBoolean out;

The actual call to the function looks like this:

Booltest(&out,&in);

Notice the Boolean variables need to take the address of their values since they were defined as being passed as pointers to values when the DLL was created.
 

Accessing LabVIEW 6i Arrays from LabWindows/CVI

 

Array Data Pointer

When you pass an array as an Array Data Pointer, you must also pass a Length Input which tells LabWindows how many elements are in the array. When you set up the parameter as an Array Data Pointer within the Define VI Prototype panel in LabVIEW, a Length Input parameter is automatically added to the function whether it is an input or output array. For an output array, you also have the option of using a Length Output parameter, which returns an integer that indicates the number of elements that were returned from the function into the associated output array. The Function Prototype for a VI that has an input array and output array with identical input lengths looks like the following:

Note: You can use either Standard or C Calling Conventions if you are using LabWindows/CVI.


To call the Arraytest function, simply add the header (.h) file and library (.lib) file to your project. Also include the header file in your source code (#include <arraytest.h>).

The variables can be created in the code in the following manner:

double arrayinput[10];
double arrayoutput[10];

The actual call to the function looks like this:

Arraytest(arrayinput, arrayoutput, 10);

Accessing LabVIEW 6i Strings from LabWindows/CVI

C String Pointer

When using LabWindows/CVI, we recommend using C String Pointers. For output strings, you also must pass a Length Input and Length Output. The Length Input tells LabWindows/CVI how many characters of the input string that you want to pass to the function. When you set up the parameter as an C String Pointer within the Define VI Prototype panel in LabVIEW, a Length Input parameter is automatically added to the function even if it is an output array. For an output array, you also have the option of using a Length Output parameter, which returns a pointer to an integer that indicates the number of characters that were returned from the function into the associated output array. The Function Prototype for a VI that has an input array and output array looks like the following:

Note: You can use either Standard or C Calling Conventions if you are going to be calling the DLLs that use arrays from LabWindows/CVI.


To call the Stringtest function, simply add the header (.h) file and library (.lib) file to your project. Also include the header file in your source code (#include stringtest.h>).

The variables can be created in the code in the following manner:

char inputstring[5] = "hello";
char outputstring[3];
long inputlength = 3;
long outputlength;

The actual call to the function looks like this:

Stringtest(inputstring, outputstring, inputlength, &outputlength);

If this function simply output the same string that was input, it returns "hel" since the Input Length is 3. The value returned to the outputlength variable also is 3, because that is the number of characters that were output into the outputstring variable. Notice that outputstring is dereferenced since it is passed as a pointer to a value.
 

Accessing LabVIEW 6i Clusters from LabWindows/CVI

When creating DLLs in LabVIEW 6i, you can pass clusters of different types of variables easily as long as the elements are not strings or arrays. It becomes more complicated when strings and arrays are involved, so we recommend not using them. The function prototype below has one cluster input and one cluster output. The types of variables contained in the cluster depend on the types of controls and indicators that are contained in the cluster within the VI. The clusters are passed as pointers to structures.

Note: You can use either Standard or C Calling Conventions if you are going to be calling the DLLs that use Clusters from LabWindows/CVI.


LabVIEW 6i automatically creates a header (.h) file and library (.lib) file which you include in your LabWindows/CVI project. For clusters, the header file contains a type definition of a structure which contains the variables that are associated with the cluster. For instance, if the input cluster above contained a numeric control and a Boolean control then the following code is automatically generated in the header file (InNum is the name of the numeric control and InBool is the name of the Boolean control):

typedef struct {
float64 InNum;
LVBoolean InBool;
} TD1;

The output cluster works in the same manner and the following code is generated:

typedef struct {
float64 OutNum;
LVBoolean OutBool;
} TD2;

Note: The structure variables TD1 and TD2 correspond to the types passed in the Function Prototype above in the panel (void ClusterTest(TD1 *InCluster, TD2 *OutCluster)).

Within the source file you must first define two new structures of type TD1 and TD2, respectively.

TD1 instr;
TD2 outstr;

Within the function you could set the input cluster values as follows:

instr.InBool = 1;
instr.InNum = 7.0;

The actual call to the function looks like this:

ClusterTest(&instr,&outstr);

The output cluster values could be used as follows:

printf("%f num %i bool",outstr.OutNum, outstr.OutBool);