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

📄 index178.htm

📁 一本不错的VC编程的参考书
💻 HTM
字号:
<html>
<style type="text/css"><!--
.p9 {  font-family: "宋体"; font-size: 9pt}a        {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">为什么DLL在字符串表中找不到字符串</font></td></tr>
<tr><td><p>
</Br>
我用向导生成器中的"Use MFC in a Shared DLL"选项建立一个DLL,在字符串表资源中加一个字符串,当我使用csMyString.LoadString( IDS_MY_STRING ) csMyString 是空的,为什么会这样?<Br>
</Br>
1)MFC是由AfxGetResourceHandle调用资源的.所以,如果你想在你的DLL中读出资源应该使用 AfxSetResourceHandle.你也可以在LoadLibrary的返回值中得到它,如果不想调用该DLL时也可以使用DLLMain函数的hInstance参数.<Br>
2)试一下在你函数打头处使用AFX_MANAGE_STATE(AfxGetStaticModuleState()) (事实上每个被外部DLL调用的每一个函数都会使用它)<Br>
3)我记得先前的列表讲过这个问题,试一下以下两种方法: 如果你是用LoadLibrary()来调用DLL的,它会返回一个句柄,你可以在 AfxSetResourceHandle()中使用它.如:<Br>
</Br>
</Br>
&nbsp;&nbsp;&nbsp;hinstnew = Loadbrary(...);<Br>
&nbsp;&nbsp;&nbsp;...<Br>
&nbsp;&nbsp;&nbsp;hinstOld = AfxGetResourceHandle();<Br>
&nbsp;&nbsp;&nbsp;AfxSetResourceHandle(hinstnew);<Br>
&nbsp;&nbsp;&nbsp;LoadString(IDS_MY_STRING);<Br>
&nbsp;&nbsp;&nbsp;AfxSetResourceHandle(hinstOld); // remember to set this back,<Br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// or your night won't be nice.<Br>
如果你不是用LoadLibrary来调用DLL又该怎样办呢?你可以使用 GetModule("You DLL Name")来取得用户句柄,剩下的就好办了.<Br>
</Br>
</p></td></tr>
</table>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -