📄 subject_33283.htm
字号:
<p>
序号:33283 发表者:zhouguosheng 发表日期:2003-03-19 10:29:58
<br>主题:为什么DLL中的凼数调用带参数时返回出错???
<br>内容: typedef void (WINAPI * TESTDLL)();<BR> HINSTANCE hmod;<BR> hmod = ::LoadLibrary ("mfcdll.dll");<BR> if(hmod==NULL)<BR> {<BR> AfxMessageBox("Fail");<BR> }<BR> TESTDLL lpproc;<BR> lpproc = (TESTDLL)GetProcAddress (hmod,"Show");<BR> if(lpproc!=(TESTDLL)NULL)<BR> (*lpproc)();<BR> <BR> FreeLibrary(hmod);<BR><BR>------------------------------<BR><BR> typedef void (WINAPI * TESTDLL)(int);<BR> HINSTANCE hmod;<BR> hmod = ::LoadLibrary ("mfcdll.dll");<BR> if(hmod==NULL)<BR> {<BR> AfxMessageBox("Fail");<BR> }<BR> TESTDLL lpproc;<BR> lpproc = (TESTDLL)GetProcAddress (hmod,"Showa");<BR> if(lpproc!=(TESTDLL)NULL)<BR> (*lpproc)(10);<BR> <BR> FreeLibrary(hmod);<BR><BR><BR><BR><BR>DLL库中函数Show()未带参数调用不会出错,<BR>DLL库中函数Showa(int ls)带参数转入时在返回主程序时出错?<BR><BR>出错提示见附件<BR><BR><BR> 多谢了!!!!<BR><BR> <BR><BR><BR><BR><BR><BR><BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:lyseed 回复日期:2003-03-19 11:59:23
<br>内容:以前遇到过,忘记怎么回事了,好象是在DLL编译时,输出函数加extern "c"就可以了.<BR>不一定对,你试试看.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:微笑的撒旦 回复日期:2003-03-19 12:24:37
<br>内容:加上extern "C"<BR>或是使用.def文件定义输出<BR>或是lpproc = (TESTDLL)GetProcAddress (hmod,"Show@4");
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:zhouguosheng 回复日期:2003-03-19 13:48:32
<br>内容:我已经用extern "C" <BR>extern "C" _declspec(dllexport) void Showa(int ls)<BR>{<BR><BR>...<BR><BR>}<BR><BR><BR>出错提示:<BR><BR>Debug Error!<BR>Program: G:\zgs\test\debug\test.exe<BR>Module:<BR>File:i386\chkesp.c<BR>Line :42<BR><BR>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.<BR><BR>(press Retry to debug the application)<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:lyseed 回复日期:2003-03-19 14:03:12
<br>内容:我使用向导生成静态连接库,完全好用,<BR>试试_declspec(dllexport)换成PASCAL EXPORT.<BR><BR>// If this DLL is dynamically linked against the MFC<BR>// DLLs, any functions exported from this DLL which<BR>// call into MFC must have the AFX_MANAGE_STATE macro<BR>// added at the very beginning of the function.<BR>//<BR>// For example:<BR>//<BR>// extern "C" BOOL PASCAL EXPORT ExportedFunction()<BR>// {<BR>// AFX_MANAGE_STATE(AfxGetStaticModuleState());<BR>// // normal function body here<BR>// }<BR>//<BR>// It is very important that this macro appear in each<BR>// function, prior to any calls into MFC. This means that<BR>// it must appear as the first statement within the <BR>// function, even before any object variable declarations<BR>// as their constructors may generate calls into the MFC<BR>// DLL.<BR>//<BR>// Please see MFC Technical Notes 33 and 58 for additional<BR>// details.<BR>//<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -