【发布时间】:2015-06-30 11:15:06
【问题描述】:
我有两个项目:一个 MFC .exe 和一个 MFC .dll。我在 DLL 中定义了一个 MFC 对话框。它有一个与之关联的资源,它还有一个派生自CDialog 的类CToolboxDiag。
对话框有一个简单的按钮,点击时会显示一个消息对话框。
void CToolboxDiag::OnBnClickedButton()
{
MessageBox(_T("Test"), _T("T"));
}
我可以将资源从 DLL 导出到我的代码中,并使用以下代码创建具有正确外观的标准 CDialog:
CDialog *diag = new CDialog;
HINSTANCE hClientResources = AfxGetResourceHandle();
//Tell the client to use the .DLL's resources
AfxSetResourceHandle(dll);
// resource_id is the resource_id in the DLL
diag->Create(resource_id, NULL);
//Restore the client application resource handle
AfxSetResourceHandle(hClientResources);
但这只会导致显示对话框,但控件(即按钮)在单击时不执行任何操作,因为它没有链接到 .exe 中的CToolboxDiag 定义。
我想导出对话框(带有按钮代码),而不必将类定义导出到 .exe。换句话说,我想导出一个功能齐全的对话框,包括它的按钮操作,而我的 .exe 上没有 CToolboxDialog 定义,这样它就可以完全模块化。我怎么能这样做?
【问题讨论】:
-
把 AFX_MANAGE_STATE(AfxGetStaticModuleState());在调用 dll 函数时
-
@SantoshDhanawade 是的,谢谢。但我想知道的是如何从 DLL 中导入 fhole 对话框功能
标签: c++ visual-c++ dll mfc