如何在项目中找到(&删除)MFC相关代码?

时间:2012-09-04 11:38:55

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

我有一个使用MFC和COM的巨大遗留项目。想法是将它迁移到Linux(winelib不适用于此),我需要识别使用MFC的代码部分。奇怪的是,该解决方案包含两个DLL项目,它们继承自CWinApp并实例化它。此外,我没有在这些DLL中看到CWinApp的用途,因为实际的GUI代码在一个单独的非dll项目中。

两个问题:
1.是否有任何工具可以帮助我找到MFC特定的代码,以便我可以删除它?已经看到了Qt option 2.为什么CWinApp在DLL项目中实例化(如下所示),而该项目根本不做任何GUI工作?它用于消息传递吗?我没有看到任何这样的语法。删除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();
}

1 个答案:

答案 0 :(得分:4)

  1. 在MFC项目设置中,将Use of MFC更改为使用 标准Windows库。然后从中删除所有包含 来自StdAfx.h的'afx'。编译错误将指导您 所有MFC特定部件!
  2. CWinApp允许您的MFC可执行文件正确使用DLL中的任何MFC代码。该框架将通过此对象初始化您的DLL。对于非MFC DLL,您只需使用DllMain
  3. 关于COM而没有MFC,我首先会使用Google搜索:atl com codeproject

相关问题