双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

关于MFC的DLL调用问题

cds27 cds27 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用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.

这是什么问题呢?该如何解决?
...全文
评论 8
收藏 已收藏
分享
返回顶部
cds27
进程/线程/DLL 15,466 成员 49,169 内容