Developer Center Resources

cancel
Showing results for 
Search instead for 
Did you mean: 

Tutorial: Creating Wrapper VIs for C/C++ DLL functions using the Import Shared Library Wizard

 

» 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

  1. Start the Import Shared Library Wizard
    (Tools » Import » Shared Library (.dll)…)  
  2. 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.  
  3. In the Select Shared Library and Header File dialog, browse to the .dll file and the .h file  

    010SelectSharedLibraryandHeaderFile.png
  4. Click Next.  
  5. 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.  
  6. 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.
    020SelectFunctionsToConver.png
    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
  7. Leave the defaults and click Next.  
  8. 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.  

    030ConfigureProjectLibrarySettings.png
  9. Click Next
  10. In the Select Error Handling Mode dialog, pick Simple Error Handling from the Error Handling Mode dropdown box and click Next.

    040SelectErrorHandlingMode.png
  11. 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.
    050ConfigureVIsAndControls.png
  12. 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.  
  13. Click Next on the Generation Summary dialog to start generating the wrapper Vis.  
  14. Click Finish to view the generated library containing the wrapper VIs. 

    060Library.png

 

 

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