Creating a shared library (DLL) that can call manager functions is very similar to creating a Code Interface Node (CIN). However, a few of the steps necessary for you to create a CIN are not necessary in creating a DLL. Notably, the DLL does not need to link against cin.obj or lvsb.lib. Also, the build does not need to include the execution of lvsbutil.exe. Be aware that functions specific to CINs, such as SetCINArraySize, do not work in a DLL.
Note: For complete documentation on how to use LabVIEW code with other programming languages in LabVIEW 7.1 or earlier, refer to the Using External Code in LabVIEW manual linked below. In LabVIEW 8.0 or later, refer to the Fundamentals»Calling Code Written in Text-Based Programming Languages book in the LabVIEW Help for more information.
To ensure that your code knows the prototypes of the manager functions and the LabVIEW data types, include extcode.h in any file that calls manager functions or uses the following LabVIEW data type notation (Int32, Bool32, etc):
If the compiler is not configured to look in the directory in which extcode.h resides, you must specify it.
#include "c:\program files\national instruments\labview\cintools\extcode.h"
To build a DLL that can access LabVIEW manager functions, you must create a multithreaded Win32 DLL and link it against labview.lib. You also should set the structure alignment to 1 byte. In the Microsoft Visual C++ IDE, complete the following steps to create a DLL to call LabVIEW manager functions.
- Select File»New and select Win32 Dynamic-Link Library as the project type to create a new DLL. Name your project.
- Select Project»Add To Project»Files and select labview.lib from the labview\Cintools\Win32 subdirectory. You will use this file to call the LabVIEW manager functions.
- Select Project»Settings and change Settings For to All Configurations. Select the C/C++ tab and Preprocessor from the Category pull-down menu. Add the path to the cintools directory in the Additional include directories field.
- Select Project»Settings and change Settings For to All Configurations. Select the C/C++ tab and set the category to Code Generation. Select 1 Byte from the Struct member alignment tab.
- Select Project»Settings and change Settings For to All Configurations. Select the C/C++ tab and set the category to Code Generation. Select Multithreaded DLL from the Use run-time library tab.
If you prefer not to link the DLL against labview.lib, you can call the LabVIEW manager functions by address. With this method, linking against labview.lib is not required, but you should follow the remainder of the steps listed previously. Calling the LabVIEW manager functions by address requires that you have an understanding of function pointers. If you do not understand the following instructions, use the first method.
Note This method does not work from within a LabVIEW built stand-alone application.
Assuming that LabVIEW is calling the DLL you are building, you can call the Win32 API function GetModuleHandle to return a pointer to the module labview.exe. You can specify NULL as the module name to return a handle to the calling module:
HMODULE hlv = GetModuleHandle(NULL);
When the calling module acquires the module handle, you can call GetProcAddress to obtain an address to the desired function:
FARPROC pNumericArrayResize = GetProcAddress(hlv, "NumericArrayResize");
When you call the function, you need to make sure the function pointer is not referenced and cast as the appropriate type:
MgErr error = (*((MgErr (__cdecl *)(int32, int32, UHandle*, int32))pNumericArrayResize)) (iL, 1, (UHandle *)&array, 50);
Notice that all manager functions use C calling conventions, not standard.
If you receive unresolved external linker errors on manager functions, it is likely that you are using CIN only functions. You can use another manager function, that is not a CIN only function, to accomplish the same job.
If you receive multiple defined symbols, try instructing the linker not to use the default libraries. In Microsoft Visual C++ IDE select Project»Settings and change Settings For to All Configurations. Select the Link tab and check Ignore Default libraries. However, you must at the very least link against kernel32.lib, user32.lib, and msvcrt.lib. Depending on the application, it may be necessary to link against other default libraries.
If you are using Microsoft Visual C/C++, and you are having difficulties with precompiled headers, you can disable the use of precompiled headers by selecting Project»Settings, clicking the C/C++ tab, selecting Precompiled Headers from the pull-down menu, and selecting Not using precompiled headers.
2. Common Applications
Data collection/generation in external code modules.