关于MFC的DLL调用问题
cds27 2009-07-02 09:17:40 我用MFC向导建立一个DLL。
.h文件:
class Cm1App : public CWinApp
{
public:
Cm1App();
// 重写
public:
virtual BOOL InitInstance();
int getx(int x);
DECLARE_MESSAGE_MAP()
};
……
.cpp文件:
int Cm1App::getx( int x )
{
return x;
}
……
def文件:
; m1.def : 声明 DLL 的模块参数。
LIBRARY "m1"
EXPORTS
; 此处可以是显式导出
getx
然后在调用时:
typedef int (*pGetx)(int x);
void CTestView::OnBnClickedButton1()
{
HINSTANCE h= AfxLoadLibrary(L"m1.dll");
if(h)
{
pGetx getx=(pGetx) GetProcAddress(h, "getx");
int x=getx(9);
}
}
结果运行时报错:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
这是什么问题呢?该如何解决?