当前位置 : 主页 > 编程语言 > c++ >

visual-c – 将资源构建到DLL中以供重用,MFC / VC

来源:互联网 收集:自由互联 发布时间:2021-06-23
例如,我想构建一个DLL,导出一个名为ShowDialog的函数,该函数显示一个对话框并更改其中一个对话框按钮中的文本.对话框和所有其他资源应捆绑在DLL中. 我做了一个快速测试,当DLL尝试使用
例如,我想构建一个DLL,导出一个名为ShowDialog的函数,该函数显示一个对话框并更改其中一个对话框按钮中的文本.对话框和所有其他资源应捆绑在DLL中.

我做了一个快速测试,当DLL尝试使用某个控件ID的GetDlgItem()时,它会返回一个空指针.我假设在这种情况下需要更多步骤来正确处理资源.

从 MSDN开始:

By default, MFC uses the resource
handle of the main application to load
the resource template. If you have an
exported function in a DLL, such as
one that launches a dialog box in the
DLL, this template is actually stored
in the DLL module. You need to switch
the module state for the correct
handle to be used. You can do this by
adding the following code to the
beginning of the function:

AFX_MANAGE_STATE(AfxGetStaticModuleState());
网友评论