关于MFC的DLL调用问题
我用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.
这是什么问题呢?该如何解决?
.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.
这是什么问题呢?该如何解决?
...全文
相关推荐
尝试mfc中dll调用adb,不成功
尝试mfc中dll调用adb实现手机助手功能,不成功,尝试mfc中dll调用adb,不成功
QT调用dll和MFC调用QT的dll
编写QT的dll,QT调用QT的dll,QT调用外部的dll,MFC程序调用QT的dll,
QT调用mfc dll和qt dll
该资源能够使用qt生成dll, 同时又mfc dll的例程,同时有使用qt调用 mfc 和qt dll的例程 。对于 学习使用qt dll很有帮助。
MFC DLL动态调用及静态调用
MFC DLL动态调用及静态调用
通过C#调用共享MFC C++项目DLL
通过C#调用共享MFC C++项目DLL


进程/线程/DLL

