» Calling External Code » Calling C/C++ DLLs » Using the Import Shared Library Wizard
Overview
This tutorial walks you through the process of automating a lot of the effort involved in calling C/C++ DLLs by using the Import Shared Library Wizard. This wizard creates wrapper VIs with pre-configured Call Library Function Nodes that you can call from your VIs.
For more details on the options in the Import Shared Library Wizard, refer to:
LabVIEW Help: Using the Import Shared Library Wizard
Example DLL
The attached sample DLL, PassingDataSampleDLL.dll, contains multiple functions with different types of parameters and return types, ranging from integers, arrays and strings to pointers and structs (clusters).
Tutorial
- Start the Import Shared Library Wizard
(Tools » Import » Shared Library (.dll)…)
- The first dialog is the Specify Create or Update Mode. We are creating a new library of wrapper VIs, so make sure the default Create VIs for a shared library radio button is selected and click Next.
- In the Select Shared Library and Header File dialog, browse to the .dll file and the .h file
- Click Next.
- We are not using any preprocessor definitions or additional include files, so leave the defaults on the Configure Include Paths and Preprocessor Definitions dialog and click Next.
- The wizard will then parse your header file and give you a list of functions that you can choose to import (create wrapper VIs for). It will also denote with an ‘X’ functions that it found but does not know how to create wrapper VIs for.
Notice that a handful of functions cannot be imported with the wizard. For details on the caveats of the Import Shared Library Wizard and how to walk around them, refer to:
Calling C/C++ DLLs Containing Simple and Complex Datatypes from LabVIEW
- Leave the defaults and click Next.
- The Configure Project Library Settings dialog allows you to name the library of wrapper VIs as well as its location. Change the path to <Tutorial>\WrapperVIs to avoid adding the VIs to your user.lib folder.
- Click Next
- In the Select Error Handling Mode dialog, pick Simple Error Handling from the Error Handling Mode dropdown box and click Next.
- The Configure VIs and Controls dialog allows you to set up the Call Library Function Nodes for each individual function. The options available here are similar to the Call Library Function Node Configuration Dialog.
- Leave the defaults and click Next. You can always go into the individual VIs and modify the Call Library Function Node at a later time.
- Click Next on the Generation Summary dialog to start generating the wrapper Vis.
- Click Finish to view the generated library containing the wrapper VIs.
Conclusion / Next Steps
You have learned how to call automatically create wrapper VIs for functions in a C/C++ DLL using the Import Shared Library Wizard.
You can also configure the inputs and outputs of these functions as well as the calling options in the Configure VIs and Controls step, or by manually changing the configuration of the Call Library Function Nodes in the individual VIs. This is particularly useful for functions that return arrays, pointers and structs.
The Import Shared Library Wizard does not handle certain cases automatically, like functions that return structs, and arrays that are referenced as pointers in the function header. For examples on how to handle these cases, refer to:
Calling C/C++ DLLs Containing Simple and Complex Datatypes from LabVIEW
Attachments
PassingDataSampleDLL.dll
PassingDataSampleDLL.h
WrapperVIs.zip
Jervin Justin
NI TestStand Product Manager