DLL dynamic-link library generation:
First open VS2012, new--Project--WIN32 console Application (project name: ConsoleApplication1)--Empty Project
Create a new source file Source.cpp
First define the function with the console EXE configuration type and debug it with the main function
You can then pass the project--Properties--Configuration Properties--general--project defaults--under Configuration type
Select the dynamic library (. dll) option
Then click Build to generate a DLL file (ConsoleApplication1.dll) in the Debug directory of the project
extern "C"_declspec (dllexport)voidmyfun (); #include"iostream"using namespacestd;voidmyfun () {cout<<"Hello World"<<Endl;}intMain () {myfun (); return 0;}
VS2012 DLL dynamic-link library invocation
First build a Win32 console empty project, build a source file yourself Source.cpp
Add header file include<windows.h>
Defines a function pointer type typedef void (*dllfun) (Note the return value type, the same as the parameter order type)
And then through HINSTANCE hdll; Create an instance handle
hDLL = LoadLibrary ("Xxxx.dll"); Loading the dynamic library
" here the string type is LPSTR, when it is the Unicode character set, it will not work, so in the project---property--General---The default character set:" Unicode "to support multi-character extension can "
Then define a function address variable dllfun myFun1;
MYFUN1 = (dllfun) GetProcAddress (hDLL, "myfun"); Gets the entry address of the Myfun function inside the dynamic library
Then MyFun1 ();
Finally release memory
Freeliabrary (hDLL);
#include"iostream"#include"windows.h"#include"time.h"using namespaceStd;typedefvoid(*Dllfun) ();intMain () {hinstance hdll; hDLL= LoadLibrary ("E:\\c++dll_lib\\consoleapplication1\\debug\\consoleapplication1.dll"); if(hDLL = =NULL) {FreeLibrary (hdll); cout<<"Dll loaded is fail ..."<<Endl; GetChar (); return-1; } Dllfun myFun1; MyFun1= (Dllfun) GetProcAddress (hDLL,"Myfun"); if(MyFun1 = =NULL) {FreeLibrary (hdll); cout<<"dlladdress loaded is fail ..."<<Endl; GetChar (); return-1; } myFun1 (); FreeLibrary (hDLL); return 0;}
Generation and invocation of dynamic libraries for C + + (VS2012) DLLs