extern "C"
{
/*
__declspec(dllexport) int Add(int a, int b);
__declspec(dllexport) int Sub(int a, int b);
__declspec(dllexport) int Mul(int a, int b);
__declspec(dllexport) int Div(int a, int b);
*/
int Add(int a, int b)
{
return (a + b);
}
int Sub(int a, int b)
{
return (a - b);
}
int Mul(int a, int b)
{
return (a * b);
}
int Div(int a, int b)
{
if (b == 0)
return 0;
else
return (a / b);
}
int Str(wchar_t *pstr)
{
MessageBox(0,pstr,0,0);
return 99;
}
}
EXPORTS
Add @1
Sub @2
Mul @3
Div @4
Str @5
调用方式:
typedef int (__cdecl *PADD )(int i,int j);
typedef int (__cdecl *PStr )(wchar_t *str);
HMODULE h = LoadLibrary("Callee.exe");
if (h == NULL)
{
printf("load error\n");
}
PADD dwAdd = (PADD)GetProcAddress(h,"Add");
int k = dwAdd(100,1000);
printf("%d",k);
PStr dwAddstr = (PStr)GetProcAddress(h,"Str");
k = dwAddstr(L"sssssssssssss"); //这里就崩溃了,就是在MessageBox的时候会崩溃,反正遇到字符串处理就必定崩溃.
printf("%d",k);
FreeLibrary(h);
If the specified module is an executable module, static imports are not loaded; instead, the module is loaded as if DONT_RESOLVE_DLL_REFERENCES was specified. See the dwFlags parameter for more information.