如何在项目中定位(和删除)MFC 依赖代码?

问题描述 投票:0回答:2

我有一个使用 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();
}
visual-studio-2010 visual-c++ mfc migration
2个回答
6
投票
  1. 在您的 MFC 项目设置中,将
    Use of MFC
    更改为 使用 标准 Windows 库。然后删除所有包含以 来自您的
    StdAfx.h
    的'afx'。编译错误将指导您 所有 MFC 特定部分!
  2. CWinApp
    允许您的 MFC 可执行文件正确使用 DLL 中的任何 MFC 代码。框架将通过此对象初始化您的 DLL。对于非 MFC DLL,您只需使用
    DllMain
    .

关于

COM
和没有MFC,我会首先谷歌搜索这个:
atl com codeproject


0
投票

对我来说 Visual Studio 2022 社区版:

  1. 项目菜单 -> 属性 -> 高级 -> 使用 MFC -> 使用标准 Windows 库
  2. 可能存在D8016'/ZI'和'/Gy-'需要注意的错误
  3. 是的,之后一切都按照上面的答案进行:“然后从 StdAfx.h 中删除所有以‘afx’开头的内容。编译错误将引导您找到所有 MFC 特定部分!”
© www.soinside.com 2019 - 2024. All rights reserved.