⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_33283.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:33283 发表者:zhouguosheng 发表日期:2003-03-19 10:29:58
<br>主题:为什么DLL中的凼数调用带参数时返回出错???
<br>内容:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef void (WINAPI * TESTDLL)();<BR>&nbsp;&nbsp;&nbsp;&nbsp;HINSTANCE hmod;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hmod = ::LoadLibrary ("mfcdll.dll");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(hmod==NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("Fail");<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;TESTDLL lpproc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;lpproc = (TESTDLL)GetProcAddress (hmod,"Show");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(lpproc!=(TESTDLL)NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (*lpproc)();<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hmod);<BR><BR>------------------------------<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typedef void (WINAPI * TESTDLL)(int);<BR>&nbsp;&nbsp;&nbsp;&nbsp;HINSTANCE hmod;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hmod = ::LoadLibrary ("mfcdll.dll");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(hmod==NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("Fail");<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;TESTDLL lpproc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;lpproc = (TESTDLL)GetProcAddress (hmod,"Showa");<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(lpproc!=(TESTDLL)NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (*lpproc)(10);<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;FreeLibrary(hmod);<BR><BR><BR><BR><BR>DLL库中函数Show()未带参数调用不会出错,<BR>DLL库中函数Showa(int ls)带参数转入时在返回主程序时出错?<BR><BR>出错提示见附件<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;多谢了!!!!<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;<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>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If this DLL is dynamically linked against the MFC<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DLLs, any functions exported from this DLL which<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;call into MFC must have the AFX_MANAGE_STATE macro<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;added at the very beginning of the function.<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For example:<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extern "C" BOOL PASCAL EXPORT ExportedFunction()<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AFX_MANAGE_STATE(AfxGetStaticModuleState());<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// normal function body here<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It is very important that this macro appear in each<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function, prior to any calls into MFC.&nbsp;&nbsp;This means that<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;it must appear as the first statement within the <BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function, even before any object variable declarations<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;as their constructors may generate calls into the MFC<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DLL.<BR>//<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please see MFC Technical Notes 33 and 58 for additional<BR>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 + -