Creating and Calling LabVIEW DLLs with Various Data Types from Microsoft Visual C++

Publish Date: Dec 21, 2006 | 11 Ratings | 2.64 out of 5 |  PDF

Overview

This document explains how to use several different data types to create LabVIEW DLLs and how to call these DLLs from Microsoft Visual C++.

Table of Contents

  1. Accessing LabVIEW 6x Numbers from Microsoft Visual C++
  2. Accessing LabVIEW 6x Booleans from Microsoft Visual C++
  3. Accessing LabVIEW 6x Arrays from Microsoft Visual C++
  4. Accessing LabVIEW 6x Strings from Microsoft Visual C++
  5. Accessing LabVIEW 6x Clusters from Microsoft Visual C++

1. Accessing LabVIEW 6x Numbers from Microsoft Visual C++

You can pass numbers in a LabVIEW function in several different ways, and you can use similar methods in Microsoft Visual C++. The following function prototype has three numeric inputs and three numeric outputs. In/Out 1 is a 32-bit integer, In/Out 2 is a double-precision, floating-point number, and In/Out 3 is an unsigned 8-bit integer. In1 and In3 are passed by value. In2 is passed as a pointer to value. The three outputs must be passed as pointers to values.

Note: Use either standard or C calling conventions when you use Microsoft Visual C++ to call DLLs that use Booleans.


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

You can create variables in the code in the following manner:

uInt8 in3 = 5;
float64 in2;
int32 in1 = 4.52;
uInt8 out3;
float64 out2;
int32 out1;

The actual call to the function should look like the following code:

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

Notice that In2 and the three outputs must take the address of their values because these inputs and outputs are passed as pointers to values.

Refer to Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass Numeric Data Types (linked below) for an example program that uses Microsoft Visual C++ to pass numbers to a LabVIEW DLL.

Back to Top

2. Accessing LabVIEW 6x Booleans from Microsoft Visual C++


When you create DLLs in LabVIEW 6x, you can pass only Boolean parameters as pointers to values. The following function prototype has one Boolean input and one Boolean output.

Note: Use either standard or C calling conventions when you use Microsoft Visual C++ to call DLLs that use Booleans.


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>).

You must create the Boolean variables in the code in the following manner:

LVBoolean in;
LVBoolean out;

The actual call to the function should look like the following code:

Booltest(&out,&in);

Notice that the Boolean variables must take the address of their values because these variables are passed as pointers to values.

Refer to Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass Booleans (linked below) for an example program that uses Microsoft Visual C++ to pass Booleans to a LabVIEW DLL.

Back to Top

3. Accessing LabVIEW 6x Arrays from Microsoft Visual C++


When you pass an array as an Array Data Pointer, you also must pass a length input that tells Microsoft Visual C++ how many elements are in the array. When you set up the parameter as an Array Data Pointer within the Define VI Prototype dialog box, LabVIEW automatically adds a length input parameter to the function for both input and output arrays. For output arrays, you also have the option of passing a length output parameter. This parameter is a pointer to the size of the output array that the function returns. The function prototype for a VI that has an input array and an output array with identical input lengths should look like the following dialog box.

Note: Use either standard or C calling conventions when you use Microsoft Visual C++ to call DLLs that use arrays.


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>).

You can create variables in the code in the following manner:

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

The actual call to the function should look like the following code:

Arraytest(arrayinput, arrayoutput, 10);

Refer to Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass C String Pointers (linked below) for an example program that uses Microsoft Visual C++ to pass arrays to a LabVIEW DLL.

Back to Top

4. Accessing LabVIEW 6x Strings from Microsoft Visual C++


When you call a DLL from Microsoft Visual C++, National Instruments recommends that you use a C String Pointer. When you use a C String Pointer, you also must pass a length input for output strings. The length input tells Microsoft Visual C++ how many characters of the input string you want to pass to the function. When you set up the parameter as a C String Pointer within the Define VI Prototype dialog box, LabVIEW automatically adds a length input parameter to the function. For output strings, you also have the option of using a length output parameter. This parameter returns a pointer to an integer that indicates the number of characters returned from the function into the associated output string. The function prototype for a VI that has an input string and an output string should look like the following dialog box.

Note: Use either standard or C calling conventions when you use Microsoft Visual C++ to call DLLs that use strings.



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

You can create variables 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 should look like the following code:

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

If the output string for the Stringtest function matches the input string, Stringtest returns hel because the Input Length is 3. The value returned to the outputlength variable also is 3, because the number of characters that were output into the outputstring variable equals 3. Notice that outputstring takes the address of the value since it is passed as a pointer to a value.

Refer to Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass C String Pointers (linked below) for an example program that uses Microsoft Visual C++ to pass strings to a LabVIEW DLL.

Back to Top

5. Accessing LabVIEW 6x Clusters from Microsoft Visual C++


When you create DLLs in LabVIEW 6x, you can pass clusters of different types of variables as long as the elements are not strings or arrays. If the elements are either strings or arrays, the process of passing clusters becomes more difficult. National Instruments recommends that you do not pass clusters if the elements of these clusters are either strings or arrays. The following function prototype has one cluster input and one cluster output. The types of controls and indicators that are contained in the cluster within the VI determine the types of variables contained in the cluster. The clusters are passed as pointers to structures.


Note: Use either standard or C calling conventions when you use Microsoft Visual C++ to call DLLs that use Booleans.


LabVIEW 6x automatically creates a header (.h) file and library (.lib) file. Include these files in your Microsoft Visual C++ project. For clusters, the header file contains a type definition of a structure that contains the variables associated with the cluster. For example, if the preceding input cluster contains a numeric control and a Boolean control, LabVIEW automatically generates the following code 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 as the input cluster, and LabVIEW automatically generates the following code in the header file:

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

Note: The structure variables TD1 and TD2 correspond to the types passed in the preceding function prototype in the Define VI Prototype dialog box (void ClusterTest(TD1 *InCluster, TD2 *OutCluster)).

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

TD1 instr;
TD2 outstr;

Within the function, you can set the input cluster values to look like the following code:

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

The actual call to the function should look like the following code:

ClusterTest(&instr,&outstr);

You can use the output cluster values as follows:

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

Refer to Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass Clusters (linked below) for an example program that uses Microsoft Visual C++ to pass clusters to a LabVIEW DLL.
Related Links:
Developer Zone: Using Microsoft Visual Basic to Call LabVIEW DLLs That Pass Numeric Data Types
Developer Zone: Using Microsoft Visual Basic to Call LabVIEW DLLs That Pass Booleans
Developer Zone: Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass C String Pointers
Developer Zone: Using Microsoft Visual C++ to Call LabVIEW DLLs That Pass Clusters
Creating DLLs Using LabVIEW 6i
Calling a DLL from Microsoft Visual C++ that Was Generated by LabVIEW 6i

Back to Top

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit