From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Dynamic Link Libraries in Visual Studio 2008 and using them in LabView

1. Open Microsoft Visual Studio 2008, and then create a new Proyect:

  • Visual C++
    • Win32
      • Console Application

Type the name of proyect, i have used creatingDLLs


1.png

2. In the wizard select:

  • Next
    • Application Type: DLL
      • Finish

2.png

3. In the solution Explorer window look the file dllmain.cpp and

  • rigth click
    • Delete

3.png

4. Delete the default content of creatingDLLs.cpp and paste the code below:

#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <ctype.h>
#include "creatingDLLs.h"

/* Define all the functions to use */

extern "C" __declspec (dllexport) long  sum_num(long, long);

BOOL APIENTRY DllMain( HANDLE hModule,
                        DWORD  ul_reason_for_call,
                        LPVOID lpReserved )
{
    return TRUE;
}


/* Add two integers */
_declspec (dllexport) long sum_num(long a, long b){
    return((long)(a+b));}


4.png


5. Create a Header file into the Headers Folder named creatingDLLs.h where the functions to be loaded in lab view will be defined; just like in the creatingDLLs.cpp file definition of functions. I.e. paste the code below into the file creatingDLLs.h

extern "C" __declspec (dllexport) long  sum_num(long, long);


6.png

6. In the Generate Menu, click Generate Solution


7.png

8. Ready!! Now look for the .dll and .h files into the working folder to create the link.

  • Open LabView, and create a .VI
    • In the Tools Menu
      • Import
        • Shared Library (.dll)...

9. Select VIs for Shared Library

  • Next
    • Locate the .dll and .h files into the folder where you created the C++ proyect
      • Next

8.png

10. Click Next, the times to be necesary till window shown below

9.png

11. And click Finish. Your Library Instance should appear. Drag the .vi file which contents the function created in c++m into the Block Diagram, and ready. You get your C++ function into LabView acting from DLL file.

10.png

Contributors