Calling a LabVIEW DLL from a LabWindows™/CVI or Other C Project

Updated Dec 15, 2022

Environment

Software

  • LabVIEW Full
  • LabVIEW Base

I compiled a dynamic link library (DLL) in LabVIEW, but I cannot figure out how to call it from LabWindows™/CVI, Visual C/C++, or other Windows development environment. How do I call a LabVIEW DLL in LabWindows/CVI or other C project?
 

When you build a DLL in LabVIEW, three files are created: a DLL file, a LIB file, and an H file. The DLL file contains the functionality that you programmed in LabVIEW. The LIB file, known as an import library, contains a stub for loading and calling the DLL functions. The H file, or header file, contains a function prototype for calling the function that is contained in the LIB file, which ultimately calls the DLL.

To use the code in another environment, you can call the DLL directly using the LoadLibrary() and GetProcAddress() functions in the Windows SDK, or you can link your project with the LIB file and H file, so that you simply call the function by name as though it were already in your project. In this case, you need to make sure that the DLL is located in the same directory as the calling assembly, and that it is in the Resource Files folder in your CVI project (create the folder if it does not exist). The following method is an example created in LabWindows/CVI illustrating the process for a direct call to a DLL created in LabVIEW:
  1. Add the .lib and .h file to the project by going to Edit > Add Files to Project... > Include (.h)... or Library(.lib)...
  2. At the top of the source file in which you wish to call your DLL, include the H file by using the #include preprocessor directive.
  3. Include other LabVIEW H files like extcode.h, fundtypes.h, and platdefines.h in the C:\Program Files(x86)\National Instruments\LabVIEW\cintools subdirectory. The previous header files define certain types used by LabVIEW and are sometimes passed in and out of LabVIEW code depending on your DLL. If LabVIEW is not installed on the development machine, you will need to copy these H files from the cintools directory to a location where the development computer can find them.
  1. Call the function by its name and parameters as specified in the header file.

Additional Information

The LabVIEW Run-Time Engine includes supporting functions that are required for any code built with LabVIEW and used on another computer. The appropriate version of the Run-Time Engine is required to execute a DLL.