谁能帮我改正错误,最好给个例子!两天没搞定了!

wdllove 2003-10-21 11:32:00
做dll传参数出错!
这是dll的!
extern "C" __declspec(dllexport) void Show(CString aa)
{

AfxMessageBox(aa);
}
这是调用!
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
typedef void (WINAPI * TESTDLL)(CString aa);
HINSTANCE hmod;
hmod = ::LoadLibrary ("mfcdll.dll");
if(hmod==NULL)
{
AfxMessageBox("Fail");
}
TESTDLL lpproc;
CString aa="bb";
lpproc = (TESTDLL)GetProcAddress (hmod,"Show");
if(lpproc!=(TESTDLL)NULL)
(*lpproc)(aa);

FreeLibrary(hmod);

}

能调用dll 显示出来对话框!
但debug 的出现一个提示框
Program: D:\TESTDLL\test\Debug\test.exe
Module:
File: i386\chkesp.c
Line: 42

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.

(Press Retry to debug the application)

而release的则自动关闭窗口


我想还是传的参数不能为cstring,或者类型不对,实在找不到问题了!:(

...全文
125 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
pxwzd123 2003-10-21
  • 打赏
  • 举报
回复
up
双杯献酒 2003-10-21
  • 打赏
  • 举报
回复
GZ
flyelf 2003-10-21
  • 打赏
  • 举报
回复
void WINAPI Show(LPCTSTR lpszMsg)
{
AfxMessageBox(lpszMsg);
}

void CTestDlg::OnOK()
{
// TODO: Add extra validation here
typedef void (WINAPI * TESTDLL)(LPCTSTR);
HINSTANCE hmod;
hmod = ::LoadLibrary ("mfcdll.dll");
if(hmod==NULL)
{
AfxMessageBox("Fail");
}
TESTDLL lpproc;
CString aa="bb";
lpproc = (TESTDLL)GetProcAddress (hmod,"Show");
if(lpproc!=(TESTDLL)NULL)
lpproc(aa);

FreeLibrary(hmod);

}
wdllove 2003-10-21
  • 打赏
  • 举报
回复
不行
---------------------------
Test: Test.exe - 应用程序错误
---------------------------
"0x77df4af8" 指令引用的 "0x00353433" 内存。该内存不能为 "read"。


要终止程序,请单击“确定”。
要调试程序,请单击“取消”。
---------------------------
确定 取消
---------------------------
akiko 2003-10-21
  • 打赏
  • 举报
回复
等一下,导出的函数原型是,默认的应该是cdecl调用约定吧,
extern "C" __declspec(dllexport) void Show(CString aa)
而你的代码中,有WINAPI,这样调用约定不用,可以编译通过吗?
typedef void (WINAPI * TESTDLL)(CString aa);
arvid_gs 2003-10-21
  • 打赏
  • 举报
回复
extern "C" __declspec(dllexport) void Show(CString &aa)
{

AfxMessageBox(aa);
}
wdllove 2003-10-21
  • 打赏
  • 举报
回复
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Error!

Program: G:\vc_study\vcDlgDLL\Test\Debug\Test.exe
Module:
File: i386\chkesp.c
Line: 42

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.

(Press Retry to debug the application)
---------------------------
终止(A) 重试(R) 忽略(I)
---------------------------
wdllove 2003-10-21
  • 打赏
  • 举报
回复
谢谢各位!
to flyelf(空谷清音) ( )
extern "C" __declspec(dllexport) void Show(LPCTSTR lpszMsg)
{
AfxMessageBox(lpszMsg);
}
void CTestDlg::OnOK()
{
// TODO: Add extra validation here

typedef void (WINAPI * TESTDLL)(LPCTSTR);
HINSTANCE hmod;
hmod = ::LoadLibrary ("mfcdll.dll");
if(hmod==NULL)
{
AfxMessageBox("Fail");
}
TESTDLL lpproc;
lpproc = (TESTDLL)GetProcAddress(hmod,"Show");
CString aa="345";
if(lpproc!=(TESTDLL)NULL)
{
(*lpproc)(aa);
}

FreeLibrary(hmod);

}

这样错误提示依然是那样!

to akiko(弥弥) ( )
我不太明白你的意思!

现在dll端能编译通过但调用不了!

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧