Il contenuto non è disponibile nella lingua selezionata.

Verrà mostrato il contenuto in un'altra delle lingue disponibili. Il tuo browser potrebbe avere delle funzionalità di traduzione.

Call a Dynamic Link Library (DLL) from LabVIEW

Updated Dec 7, 2020

Environment

Software

  • LabVIEW

Programming Language

  • C
  • C++
  • C# .NET

If you have code written in C, C++, or another programming language, you can utilize it in LabVIEW by calling the Dynamically Linked Library (DLL) that it is a part of. This tutorial explains how options for how to load DLLs into LabVIEW. This tutorial assumes familiarity with DLLs and their associated files.

Before You Begin

There are multiple ways to import code from other program languages into LabVIEW. To determine which method you should use, consider the following:
  1. Is your library a C/C++ DLL or a Microsoft .NET Assembly/.NET DLL?  To determine what type of library you have, you can check the Portable Executable (PE) header for the DLL files. 
    • If you are using a Microsoft .NET Assembly, continue to the Import .NET Assembly Functions with Constructor Node section below.
  2. Do you have a header (*.h) file for your C/C++ DLL?
    • If you do not have a header file, continue to the Manually Configure DLL Functions Using Call Library Function Node section.
  3. What data types does your function(s) utilize?
    • If the function(s) you want to call utilizes supported data types, you can proceed with using the Import Shared Library Wizard. Continue to the Import Functions with Import Shared Library Wizard section.
    • If your function(s) use complex or unsupported data types, you can use the Call Library Function node to import and format the functions manually. Continue to the Configure DLL Functions Using Call Library Function Node section.
To accompany the steps below, The LabVIEW Example Finder has complete and functional examples of how to properly call external code in LabVIEW. See Help >> Find Examples... >> Communicating with External Applications.
 

Import DLL Functions with Import Shared Library Wizard

If you have a header file and you are using supported data types, you can use the Import Shared Library Wizard to import your DLL functions into LabVIEW. This tool parses the header file, lists the functions in the shared library, converts data types in the shared library to LabVIEW data types, and generates a wrapper VI for each function. The wizard saves the VIs in a LabVIEW project library. Continue to the Use Header File with the Import Shared Library Wizard section.

A full set of instructions to configure the Import Shared Library Wizard is available in the LabVIEW Help. Briefly, you can start your import by:
  1. Launch LabVIEW and navigate to Tools >> Import... >> Shared Library (.dll) to launch the Import Shared Library Wizard.
  2. Select Create VIs for a shared library and then Next
  3. Input the file paths for the Shared Library (.dll) File and Header (.h) File
  4. Continue configuring each page as needed, importing your desired functions, and selecting Next.
  5. When finished with configuration, select Finish to create your LabVIEW Project library (.lvlib) file.
For an example of how to import a DLL using the Import Shared Library Wizard, follow Example: Importing Functions from a Shared Library File from the LabVIEW Help.
 

 

Configure DLL Functions Using Call Library Function Node

If you do not have a header file or you are using unsupported data types in your C/C++ DLL, use the Call Library Function Node to manually pull in desired functions from the DLL and format the expected inputs and outputs. 
  1. Launch LabVIEW and open a new VI. 
  2. On the block diagram, add a Call Library Function Node and double-click the node to launch the configuration window.
  3. Configure the Call Library Function Node using the dialog box, pulling in the function and formating input and output parameters. 
    1. On the Function tab of the configuration window, enter the path to the DLL and select the function you wish to call. 
  1. Navigate to the Parameters tab in the configuration window. Here you will add parameters and modify the return type until the function prototype at the bottom of the window matches the DLL's function definition.
    • If the function(s) you wish to call contains complex data types, you'll need to manually define the function prototype within the configuration dialog in the Call Library Function Node (if the DLL has been compiled with a Type Library,  the parameter data and return types will be defined automatically).
  1. Continue Configuring the Call Library Function Node using the dialog box with desired settings. When complete, select OK to update the Node on the block diagram to display the input and output terminals with the configured data types. 



Import .NET Assembly Functions with Constructor Node

A .NET DLL, also called a .NET assembly, is useful in .NET programming. A .NET DLL uses the Common Language Runtime (CLR) and the .NET Framework to manage the functions within the DLL. You can use a .NET Contructor Node to put in the functions from a .NET Assembly.

In order to use a .NET assembly in LabVIEW, simply use the .NET palette (Connectivity».NETto find all of the functions available.
  1. Launch LabVIEW and open a new VI.
  2. Add a Constructor Node to the block diagram.
  3. Use a Constructor Node in order to instantiate a class within the .NET assembly. This can be done by double-clicking the Constructor Node to bring up the Select .NET Constructor dialog box. 
  4. Configure the Constructor Node using the dialog box based on the functions you are calling.
 
  1. Use Property and Invoke Nodes to access properties and methods of the class by simply wiring in the class reference from the Constructor Node to the Property or Invoke Node. 
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

 

Refer to 

Access examples of using the Constructor Node function in the LabVIEW Example Finder or in filepath labview\examples\Connectivity\Dot NET.