如何将MFCVC项目中的资源构建到DLL中,实现跨项目重用?

2026-04-16 18:095阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计272个文字,预计阅读时间需要2分钟。

如何将MFC/VC项目中的资源构建到DLL中,实现跨项目重用?

例如,我想构建一个DLL,导出一个名为ShowDialog的函数。该函数显示一个对话框,并允许更改其中按钮的文本。对话框及其资源绑定在DLL中。我进行了快速测试,当DLL进行测试时使用。

例如,我想构建一个DLL,导出一个名为ShowDialog的函数,该函数显示一个对话框并更改其中一个对话框按钮中的文本.对话框和所有其他资源应捆绑在DLL中.

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

从 MSDN开始:

如何将MFC/VC项目中的资源构建到DLL中,实现跨项目重用?

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());

本文共计272个文字,预计阅读时间需要2分钟。

如何将MFC/VC项目中的资源构建到DLL中,实现跨项目重用?

例如,我想构建一个DLL,导出一个名为ShowDialog的函数。该函数显示一个对话框,并允许更改其中按钮的文本。对话框及其资源绑定在DLL中。我进行了快速测试,当DLL进行测试时使用。

例如,我想构建一个DLL,导出一个名为ShowDialog的函数,该函数显示一个对话框并更改其中一个对话框按钮中的文本.对话框和所有其他资源应捆绑在DLL中.

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

从 MSDN开始:

如何将MFC/VC项目中的资源构建到DLL中,实现跨项目重用?

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());