我有一个使用 MFC 和 COM 的巨大遗留项目。将其迁移到 Linux 的想法(winelib 不适用于此),我需要确定使用 MFC 的代码部分。奇怪的是,该解决方案包含两个从 CWinApp 继承并实例化它的 DLL 项目。此外,我在这些 DLL 中看不到 CWinApp 的用途,因为实际的 GUI 代码位于单独的非 DLL 项目中。
两个问题:
1. 有什么工具可以帮助我找到 MFC 特定代码以便删除它吗?已经看到Qt选项。
2. 为什么 CWinApp 在一个根本不做任何 GUI 工作的 DLL 项目中实例化(如下所示)?它用于消息传递吗?我没有看到任何这样的语法。删除 CWinApp 实例化会导致另一个项目的指针未被初始化。诡异的!
一个 DLL 项目的代码是这样的:
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "dlldatax.h"
//removed some project-specific includes for posting on SO
#ifdef _MERGE_PROXYSTUB
extern "C" HINSTANCE hProxyDll;
#endif
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_MyManager, CMyManager)
//removed some other similar lines as the line above
END_OBJECT_MAP()
// Component Category Helper Functions
static HRESULT CreateComponentCategory( CATID catid, WCHAR* catDescription );
static HRESULT UnRegisterCategory( CATID catid );
class CMyClassWrapperApp : public CWinApp
{
public:
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyClassWrapperApp, CWinApp)
END_MESSAGE_MAP()
CMyClassWrapperApp theApp;
BOOL CMyClassWrapperApp::InitInstance()
{
#ifdef _MERGE_PROXYSTUB
hProxyDll = m_hInstance;
#endif
_Module.Init(ObjectMap, m_hInstance, &LIBID_MyClassWrapperLib);
return CWinApp::InitInstance();
}
int CMyClassWrapperApp::ExitInstance()
{
_Module.Term();
return CWinApp::ExitInstance();
}
Use of MFC
更改为 使用
标准 Windows 库。然后删除所有包含以
来自您的StdAfx.h
的'afx'。编译错误将指导您
所有 MFC 特定部分!CWinApp
允许您的 MFC 可执行文件正确使用 DLL 中的任何 MFC 代码。框架将通过此对象初始化您的 DLL。对于非 MFC DLL,您只需使用 DllMain
.关于
COM
和没有MFC,我会首先谷歌搜索这个:atl com codeproject
对我来说 Visual Studio 2022 社区版: