LabVIEW developers often have to call C/C++ DLLs from LabVIEW and because of the differences between LabVIEW and C/C++ datatypes, passing and receiving data from these DLLs can be intimidating at first.
This example seeks to show developers how to pass and receive different types of data ranging from simple datatypes like numerics (int, float, double, etc), arrays and strings to more complex data types like pointers, struct (cluster), arrays of structs, and even arrays of structs that have arrays of structs in them.
In addition, this example seeks to show developers the different ways to pass and receive data in LabVIEW with a DLL – when functions pass data by value, return data using a return statement, or return data using pass by reference.
This example covers the following use cases:
|1. Numeric (Integer)
|a) Returning a value (return statement)
|2. Array of Numerics
|b) Returning a pointer (return statement)
|c) Passing a parameter (Pass by value)
|4. 2 Dimensional Array
|d) Returning values by reference (pass by ref)
|5. Simple Struct (with basic datatypes)
|6. Complex Struct (with structs & arrays)
The majority of VIs in the example were automatically generated using the Import Shared Library Wizard. The wizard does not cover all cases, and could not generate VI wrappers for some functions, and some VI wrappers were incomplete. However, it gives us a really good starting point for calling our DLL.
For an example on using the Import Shared Library Wizard, refer to:
Tutorial: Creating Wrapper VIs for C/C++ DLL functions using the Import Shared Library Wizard
For an explanation on what the Import Shared Library Wizard missed, refer to the section titled Caveats with the Import Shared Library Wizard.
The VIs in the example are arranged in the following virtual folders in the library:
The following cases were not completely handled by the Import Shared Library Wizard:
In the following case, VIs were not generated at all:
In the example lvlib, these VIs were manually created and given the suffix “Added” to the name.
In the following cases, the VIs that were generated were incomplete in some fashion:
In the example lvlib, these VIs completed in a new VI that has the suffix “Complete” in the name.
In the following cases, the VIs that were generated had some incorrect behavior:
In the example lvlib, these VIs were corrected in a new VI and given the suffix “Corrected” to the name.
The following is a list of functions exposed by the C DLL as well as the VI that shows how to properly call the particular function.
For a spreadsheet view, refer to:
Passing data between LabVIEW and C/C++ DLLs can be challenging especially when dealing with complex data types and pointers. Use the VIs in this example as a reference when you need to call DLLs from LabVIEW.