我有一个巨大的遗留项目,它使用 MFC 和 COM。将其迁移到 Linux 的想法(winelib 不适用于此),我需要确定使用 MFC 的代码部分。奇怪的是,该解决方案包含两个 DLL 项目,它们继承自 CWinApp 并对其进行实例化。此外,我在这些 DLL 中看不到 CWinApp 的用途,因为实际的 GUI 代码在一个单独的非 dll 项目中。
两个问题:
1. 有没有什么工具可以帮我找到 MFC 特定的代码,以便我可以删除它?已经看到Qt option .
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 库 .然后删除所有以开头的包含
'afx' 来自您的
StdAfx.h
.编译错误将引导您所有 MFC 特定部件!
CWinApp
是否允许您的 MFC 可执行文件正确使用您的 DLL 中的任何 MFC 代码。框架将通过此对象初始化您的 DLL。对于非 MFC DLL,您只需使用 DllMain
. 关于
COM
没有 MFC,我会先用谷歌搜索:atl com codeproject
关于visual-studio-2010 - 如何在项目中定位(和删除)MFC 相关代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12262715/