【发布时间】:2011-03-10 08:27:02
【问题描述】:
我最近遇到了一个 DLL (github),它使用 MFC 对话框(例如,它导入 "afxdlg.h" 并调用 CFileDialog)并且似乎静态链接到 MFC,但没有类基于CWinApp。我有点困惑:它是不是 MFC DLL?怎么没有CWinApp?
改述:在 Win32 DLL 中,我使用一些 MFC 类(例如,我包含 "afxdlgs.h" 并使用 CFileDialog)并静态链接 MFC。没有DllMain。最终的 DLL 是否有来自 Win32 或来自 MFC 的DllMain?
如果它选择 MFC 版本,那么另一个问题:使用 DllMain(无线程)制作 Win32 DLL 以使用 MFC DllMain 的最简单方法是什么?以下是正确的吗?
#include "afx.h" /* correct? */
class MyDll: public CWinApp
{
public:
/* do I need constructor and destructor here? */
virtual BOOL InitInstance();
virtual BOOL ExitInstance();
} theDll;
BOOL
MyDLL::InitInstance()
{
CWinApp::InitInstance();
/* code from old DllMain, DLL_PROCESS_ATTACH.
For hInst use theDll.m_hInstance */
return TRUE;
}
BOOL
MyDLL::ExitInstance()
{
/* code from old DllMain, DLL_PROCESS_DETACH */
return CWinApp::ExitInstance();
}
【问题讨论】: