GetProcAddress()获取多参数函数的问题
#ifndef DLLEXPORT
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
extern "C" DLLEXPORT int f(int a,int b);
首先导出一个函数f,他有两个参数
f函数的实现为
extern "C" int f(int a,int b)
{
return a+b;
}
在主函数里面获取函数地址的方法为:
HMODULE hModule = LoadLibrary("..\\DLL\\Debug\\Dll");
typedef int (WINAPI* lpFunction)(int,int);
if(hModule)
{
lpFunction f = (lpFunction)GetProcAddress( hModule, "f");
if(f)
{
CString s;
int a = f(2,3);//运行这一步就直接失败了??????出错信息为The value of ESP was
//saved across a function call!
s.Format("Sum of a and b is:%d",a);
MessageBox(s);
//f(2,3);
}
else
{
AfxMessageBox("GetProcAddress失败!");
GetLastError();
}
FreeLibrary(hModule);
}
else
{
AfxMessageBox("LoadLibrary失败!");
}
请问问什么会错误呢??
我如果用void型的函数,就不会出错!!
谢谢!!