There are two methods to call a DLL: static call and dynamic call.
(1) The static call procedure is as follows:
1. Copy your youapp. DLL to the DEBUG directory of your target project (the project of youapp. DLL needs to be called;
2. Copy your youapp. lib to the directory of your target project (the project of youapp. DLL needs to be called;
3. Copy your youapp. H (including the definition of the output function) to your target project (you need to call the project of youapp. dll ).
Directory;
4. Open the selected project of your target project and select the settings menu of the Project Main Menu of Visual C ++;
5. After step 4 is executed, VC will pop up a dialog box, and select the link page in the Multi-page display control of the dialog box. However
Enter youapp. Lib in the object/library modules input box.
6. Select your target project head files and add: youapp. h file;
7. At last, include your: # include "youapp. H" in your target project (*. cpp, you need to call the function in DLL"
Note: youapp is the project name of your DLL.
2. Call it dynamicallyProgramAs follows:
For dynamic calls, you only need to perform static call step 1.
{
Hinstance hdllinst = loadlibrary ("youapp. dll ");
If (hdllinst)
{
Typedef DWORD (winapi * myfunc) (DWORD, DWORD );
Myfunc youfuntionnamealias = NULL; // youfuntionnamealias function alias
Youfuntionnamealias = (myfunc) getprocaddress
(Hdllinst, "youfuntionname ");
// The Name Of The function declared by youfuntionname in DLL
If (youfuntionnamealias)
{
Youfuntionnamealias (param1, param2 );
}
Freelibrary (hdllinst );
}
}
Explicit (static) call:
Lib + dll +. H. Note that the dllexport in. H is changed to dllimport.
Implicit (dynamic) call:
Dll + function prototype declaration, loadlibrary first, and then getprocaddress (that is, find the address of the function in DLL), without freelibrary