To create a DLL project:
1#include"CustomDll.h"2#include <windows.h>3 BOOL apientry DLLMAIN (hmodule hmodule, DWORD reason_for_call, lpvoid lpreserved)4 {5 Switch(Reason_for_call)6 {7 CaseDll_process_attach:8 CaseDll_process_detach:9 CaseDll_thread_attach:Ten CaseDll_thread_detach: One Break; A } - returnTRUE; - } the intDllfuncadd (intAintb) - { - returnA +b; -}
Create Usedll project, implicitly dynamic Link: Copy the DLL project to the Usedll project root, then use the following code
1#include <windows.h>2#include"CustomDll.h" 3#include <iostream>4 using namespacestd;5 #pragmaComment (lib, "Customdll")6 intMain ()7 {8 intc =1, B =2;9cout << Dllfuncadd (c, b) <<Endl;Ten return 0; One}
Show Dynamic Link: Click Project in original DLL project, add new item, check module definition file (. def), then name input DLL, determine
Add the following code to the Dll.def file:
1 exports 2 Dllfuncadd
Then edit the Usedll project in the following code:
1#include <windows.h>2#include <iostream>3 using namespacestd;4typedefint(*pfnexportfunc) (intAintb);5 intMain ()6 {7 intc =1, B =2;8hmodule hmodule = LoadLibrary (L"CustomDll.dll");9 if(Hmodule! =NULL)Ten { OnePfnexportfunc Mdllfuncadd = (pfnexportfunc) GetProcAddress (hmodule,"Dllfuncadd"); A if(Mdllfuncadd! =NULL) - { -cout << Mdllfuncadd (c, b) <<Endl; the } - FreeLibrary (hmodule); - } - + return 0; -}
On the line.
Dynamic link Library's implicit dynamic link and display dynamic link