concentrate on c/c++ related technology

plan,refactor,daily-build, self-discipline,

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  37 Posts :: 1 Stories :: 12 Comments :: 0 Trackbacks

常用链接

留言簿(9)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

在vc6里面一般都没有这个头文件的,在后面的版本(.NET)都有相关的说明,不过这个是CString包含的头文件,我之前将open source的代码移植到win32 application平台下面,对方的编译器是vc2003,而我的是用到了vc6,所以就遇到这个问题了,解决办法有两种:
1)在工程里面加入MFCsupport,因为CString是MFC里面的内容。具体做法是project/settings/General/microsoft foundation class处选择using MFC as a shared dll./ static library.
在msdn上面有具体的说明。
可能看起来比较麻烦,不过不好意思,就这样弄过来防止msdn上面这个文章过旧了,又被删除了。

给 ATL EXE 项目添加 MFC 支持



1. 在包括 Atlbase.h 之前,将以下 #include 指令添加到 StdAfx.h:
      #include <afxwin.h>   // MFC core and standard components
            #include <afxext.h>   // MFC extensions
            #include <afxdisp.h>  // MFC Automation extensions
2. 更改项目设置以使用 MFC。 在 Project Settings 对话框中,单击 General 选项卡,然后将 Microsoft Foundation Classes 列表框中的设置更改为 MFC。
3. 添加 CWinApp 衍生类,并声明一个该类型的全局变量,如下所示:
class CMyApp : public CWinApp
            {
            public:
            virtual BOOL InitInstance();
            virtual int ExitInstance();
            protected:
            BOOL m_bRun;
            };
4. 用以下 InitInstance 和 ExitInstance 代码替换 _tWinMain 函数:
BOOL CMyApp::InitInstance()
            {
            // Initialize OLE libraries.
            if (!AfxOleInit())
            {
            AfxMessageBox(_T("OLE Initialization Failed!"));
            return FALSE;
            }
            // Initialize CcomModule.
            _Module.Init(ObjectMap, m_hInstance);
            _Module.dwThreadID = GetCurrentThreadId();
            // Check command line arguments.
            TCHAR szTokens[] = _T("-/");
            m_bRun = TRUE;
            LPCTSTR lpszToken = FindOneOf(m_lpCmdLine, szTokens);
            while (lpszToken != NULL)
            {
            // Register ATL and MFC class factories.
            if (lstrcmpi(lpszToken, _T("Embedding"))==0 ||
            lstrcmpi(lpszToken, _T("Automation"))==0)
            {
            AfxOleSetUserCtrl(FALSE);
            break;
            }
            // Unregister servers.
            // There is no unregistration code for MFC
            // servers. Refer to <LINK TYPE="ARTICLE" VALUE="Q186212">Q186212</LINK> "HOWTO: Unregister MFC
            // Automation Servers" for adding unregistration
            // code.
            else if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
            {
            VERIFY(SUCCEEDED(_Module.UpdateRegistryFromResource(IDR_ServerS2B, FALSE)));
            VERIFY(SUCCEEDED(_Module.UnregisterServer(TRUE)));
            m_bRun = FALSE;
            break;
            }
            // Register ATL and MFC objects in the registry.
            else if (lstrcmpi(lpszToken, _T("RegServer"))==0)
            {
            VERIFY(SUCCEEDED(_Module.UpdateRegistryFromResource(IDR_ServerS2B, TRUE)));
            VERIFY(SUCCEEDED(_Module.RegisterServer(TRUE)));
            COleObjectFactory::UpdateRegistryAll();
            m_bRun = FALSE;
            break;
            }
            lpszToken = FindOneOf(lpszToken, szTokens);
            }
            if (m_bRun)
            {
            // Comment out the next line if not using VC 6-generated
            // code.
            _Module.StartMonitor();
            VERIFY(SUCCEEDED(_Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE)));
            VERIFY(COleObjectFactory::RegisterAll());
            // To run the EXE standalone, you need to create a window
            // and assign the CWnd* to m_pMainWnd.
            LPCTSTR szClass = AfxRegisterWndClass(NULL);
            m_pMainWnd = new CWnd;
            m_pMainWnd->CreateEx(0, szClass, _T("SomeName"), 0, CRect(0, 0, 0, 0), NULL, 1234);
            }
            return TRUE;
            }
            int CMyApp::ExitInstance()
            {
            // MFC's class factories registration is
            // automatically revoked by MFC itself.
            if (m_bRun)
            {
            _Module.RevokeClassObjects();
            Sleep(dwPause); //wait for any threads to finish
            }
            _Module.Term();
            return 0;
            }
5. 对于 Unicode 版本,请确保进入点被设置为 wWinMainCRTStartup,该设置在 Project Settings 对话框中 Link 字段的 Output 类别中。 有关其它信息,请参见 Microsoft Knowledge Base 中的下列文章:
125750 (http://support.microsoft.com/kb/125750/EN-US/) PRB: 错误 LNK2001: “_WinMain@16”: 不能解析的外部符号
6. 将以下代码行添加到 COM 接口、窗口过程和导出函数的每个成员函数的开头:
AFX_MANAGE_STATE(AfxGetAppModuleState());
有关 AFX_MANAGE_STATE 的详细信息,请查询 VC++ 联机文档。
有关将 MFC 支持添加到 ATL COM AppWizard 项目的详细信息,请参见下面的 Microsoft Knowledge Base 文章:

181505 (http://support.microsoft.com/kb/181505/EN-US/) PRB: ATL COM AppWizard 不提供对 .EXE 的 MFC 支持

回到顶端

将 MFC 支持添加到 ATL DLL 项目



执行上面的步骤 1 到步骤 3。

1. 将 AppWizard 生成的 DllMain 的 DLL_PROCESS_ATTACH 和 DLL_PROCESS_DETACH 中的代码移到 CMyApp 的 InitInstance 和 ExitInstance,并删除 DllMain,如下所示:
      BOOL CMyApp::InitInstance()
            {
            _Module.Init(ObjectMap, m_hInstance);
            return CWinApp::InitInstance();
            }
            int CMyApp::ExitInstance()
            {
            // MFC's class factories registration is
            // automatically revoked by MFC itself.
            if (m_bRun)
            _Module.RevokeClassObjects();
            
2. 将以下代码行添加到 COM 接口、窗口过程和导出函数的每个成员函数的开头:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
有关其它信息,请参见 Microsoft Knowledge Base 中的下列文章:
140850 (http://support.microsoft.com/kb/140850/EN-US/) HOWTO: 转换 DLLTRACE 以使用共享库中的 MFC

另外一种办法就是将atlstr废掉,采用其他办法
因为atlstr实际起作用的是CString,而如果能够找到CString的替代方案,就可以了。
替代方案在这里:
http://www.codeguru.com/forum/showthread.php?t=402543
一般建议用std::string来完成这些不依赖微软某种技术的做法。
在我的项目里面,因为采用的是win32 application工程,并且该项目已经很大了,不想因为这个而在那里增加一些方案1的处理,我采用了方案2。
posted on 2008-04-29 10:14 jolley 阅读(7996) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理