To download NI software, including the products shown below, visit ni.com/downloads.
Overview
The example will guide you through using DLLs built using Visual C++ in the C compiler of LabWindows/CVI
Description
While calling C based DLLs in LabWindows/CVI is a breeze, calling DLLs built in other languages such as Visual C++ can be somewhat more involved. This example will demonstrate how to properly set up a project in Microsoft Visual Studio to build a visual C++ DLL. Then, we will call functions from that DLL in LabWindows/CVI.
Requirements
Steps to Implement or Execute Code
extern "C" __declspec(dllexport) double __cdecl DGAdd(double a, double b); | |
extern "C" __declspec(dllexport) double __cdecl Subtract(double a, double b); | |
extern "C" __declspec(dllexport) double __cdecl Multiply(double a, double b); |
Additional Information or References
Refer to Section 9 of FAQ: Using Dynamic Link Libraries with NI LabWindows/CVI
Calling a Visual Basic DLL From LabWindows/CVI
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Creating the DLL is not discussed. Is it assumed that the C++ DLL has already been built and we then have to add the extern "C"? Or do add that before we create the DLL? Thanks.
Hi!
You would do that before you create the DLL as noted in step 2 and three. You have to add the modifiers to the .h file and then build the project.
In the calling program, include the .h and .lib file and we will be able to call the functions. The attached .zip file contains the example code on how to accomplish this on both the creating the .dll side and calling it. I hope this helps!
Regards,
Ale
Hi Ale,
Thanks for the quick response and I understand it now. But nowhere does it say build DLL now. It’s kind of implied in Step 3, but not stated outright. Perhaps it’s obvious to a programmer experienced in this, but I’ve never built a DLL before, so I need it spelled out. Thanks again for your help.
Bill
Hi,
i am trying to use C function that wrapped C# dll and call it via CVI, without success. can you advice please?
Hi,
thank you very much indeed for very useful example code
Hello,
I'm getting errors when attempting step 8. Below is the build output:
Command-line Application.c - 6 errors, 4 warnings "MathFuncsDll.h"(2,12) Warning: Empty declaration. "MathFuncsDll.h"(2,12) syntax error; found 'string constant' expecting ';'. "MathFuncsDll.h"(2,12) Unrecognized declaration. "MathFuncsDll.h"(3,12) Warning: Empty declaration. "MathFuncsDll.h"(3,12) syntax error; found 'string constant' expecting ';'. "MathFuncsDll.h"(3,12) Unrecognized declaration. "MathFuncsDll.h"(4,12) Warning: Empty declaration. "MathFuncsDll.h"(4,12) syntax error; found 'string constant' expecting ';'. "MathFuncsDll.h"(4,12) Unrecognized declaration. 55, 1 Warning: HIPAR tag - Parameter help for name declared but parameter not defined in function.
I haven't modified the CVI project or the C++ code. I am running CVI 9.0