# include
# include & lt; Fstream>
# include//this header file is very important, must add!
using namespace std;
Dllfunc typedef int (*) ();//the dllfun form here and we generate the function in the DLL file is consistent, we defined the DLL function has two integer parameter, so here is the int a, int b
Int main ()
{
HINSTANCE HDLL;//define a handle to the instance, to get the DLL instance address
//here for the sake of simplicity, we will directly generate multiply. DLL files are copied to the current project, otherwise the following sentence you need to replace the address of the DLL
STD: : ofstream outfile (" ConsoleApplication2. DLL ");
HDLL=LoadLibrary (TEXT (" ConsoleApplication2. DLL "));//load generated DLL files, because we copy generated DLL file to the current project directory, so I just write directly
//the following whether the current DLL loading success
If (HDLL==NULL)
{
cout <"DLL load failed" & lt;getchar();
getchar();
return 0;
}
//if through the above suggests that loading is successful, the following we need to take out the address of the DLL function inside the
Dllfunc sc_obj=(dllfunc) GetProcAddress call (HDLL, "sc");//here two parameter a is our handle, the other is the DLL function name, out to add_obj
//in the same way, address the success? Judge it!
If (sc_obj==NULL)
{
cout <"Failed to get the DLL function address!"getchar();
getchar();
return 0;
}
//to get after the success of the function's address, we can use the function in the DLL
coutFreeLibrary (HDLL);
getchar();
return 0;
CodePudding user response:
STD: : ofstream outfile (" ConsoleApplication2. DLL ");
This code is why ah, don't you give the file to take up, so I can't load, delete,
CodePudding user response:
Sc C export function?Extern "c"
Use the depends to see
CodePudding user response:
After failure, with getlasterror get error codeThe specific method of use, check the MSDN
CodePudding user response:
Learn how to use dumpbin. Exe view DLL,