Tags: dllc++2010threadlibrarycThis article has been included in:Classification:C + +
(103) Author of similar articles
X
first, the creation of DLLs
Create Project: Win32->win32 project, Name: MyDLL
Select DLL (D) to finish.
1. New header file testdll.h
The testdll.h code is as follows:
#ifndef Testdll_h_
#define Testdll_h_
#ifdef Mylibdll
#define Mylibdll extern "C" _declspec (dllimport)
#else
#define Mylibdll extern "C" _declspec (dllexport)
#endif
Mylibdll int Add (int plus1, int plus2);
Can also write like this:
extern "C" {
_declspec (dllexport) int Add (int plus1, int plus2);
//};
#endif
2. New source file Testdll.cpp
The Testdll.cpp code is as follows:
#include "stdafx.h"
#include "testdll.h"
#include <iostream>
using namespace Std;
int Add (int plus1, int plus2)
{
int add_result = Plus1 + plus2;
return add_result;
}
3. New module definition file
Mydll.def
The MYDLL.DEF code is as follows:
LIBRARY "MyDLL"
Exports
ADD @1
4. VS2010 automatically creates the Dllmain.cpp file, which defines the entry point of the DLL application.
The Dllmain.cpp code is as follows:
Dllmain.cpp: Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL apientry DllMain (hmodule hmodule,
DWORD Ul_reason_for_call,
LPVOID lpreserved
)
{
Switch (Ul_reason_for_call)
{
Case Dll_process_attach:
Case Dll_thread_attach:
Case Dll_thread_detach:
Case Dll_process_detach:
Break
}
return TRUE;
}
Finally, compile the build MyDLL.dll file and the MyDLL.lib file.
1>------Started Build: Project: MyDLL, configuration: Debug Win32------
1> Dllmain.cpp
========== Generation: Success 1, failure 0, latest 0, skip 0 ==========
1>------Started Build: Project: MyDLL, configuration: Debug Win32------
1> Stdafx.cpp
1> Testdll.cpp
1> MyDLL.cpp
1> is generating code ...
1> Creating library D:\Visual c++\ Engineering \libaray\mydll\debug\mydll.lib and Objects D:\Visual c++\ project \libaray\mydll\debug
"Go" VS2010 creating DLL plots in C + +