visual-studio-2010 - 如何在项目中定位(和删除)MFC 相关代码?

标签 visual-studio-2010 visual-c++ mfc migration

我有一个巨大的遗留项目,它使用 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();
}

最佳答案

  • 在您的 MFC 项目设置中,更改为 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/

    相关文章:

    c++ - lineEdit 的显示困惑 - Qt

    c# - 如何计算 C#.net 中文件的 CRC 值?

    c++ - 将包含/库目录和链接器参数传播到解决方案中的所有项目?

    c++ - 树控件的 NM_TREEVIEW*

    c++ - Visual C++ 如何使用 CPaintDC、CDC 在 CView 中重绘图像

    c++ - 为什么 CFindFile 函数 GetFilePath、GetFileName 返回十六进制输出?

    c# - 如何在 C# 应用程序之间同时同步数据刷新

    c - fflush(stdin) 不能在 cygwin 中用 gcc 编译,但可以用 visual studio 2010 编译

    c++ - 找到MFC Dialog的当前位置

    visual-studio-2010 - 错误: A newer version of Microsoft Visual C++ 2010 Redistributable has been detected on the machine