怎样让ATL支持MFC呢?

lye 2004-07-15 11:58:02
谢谢先!
...全文
239 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjzxyg 2004-08-06
  • 打赏
  • 举报
回复
直接新建工程时选择支持mfc不是最简单么
四大皆空相 2004-08-06
  • 打赏
  • 举报
回复
to gracezhu(eutom)

very good!!
xpf_2000 2004-07-20
  • 打赏
  • 举报
回复
向导中选择 support MFC
msvbvm60 2004-07-17
  • 打赏
  • 举报
回复
向导好象有支持MFC的选项吧
lye 2004-07-15
  • 打赏
  • 举报
回复
还有其他方法吗?
gracezhu 2004-07-15
  • 打赏
  • 举报
回复
Adding MFC Support to an ATL EXE Project
Add the following #include directives to StdAfx.h prior to including Atlbase.h:



#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation extensions
Change project settings to use MFC. From the Project Settings dialog box, click the General tab, and change the setting in the "Microsoft Foundation Classes" list box to MFC.


Add a CWinApp derived class and declare a global variable of that type as follows:



class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
protected:
BOOL m_bRun;
};
Replace the _tWinMain function with the following InitInstance and ExitInstance code:



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;
}
For Unicode builds, make sure the entry point is set to wWinMainCRTStartup in the Output category of the Link field in the Project Settings dialog box. For additional information, please see the following article in the Microsoft Knowledge Base:


Q125750 PRB: Error LNK2001: '_WinMain@16': Unresolved External Symbol
Add the following line of code to the beginning of every member function of a COM interface, window procedure, and exported function:

AFX_MANAGE_STATE(AfxGetAppModuleState());
For more information on AFX_MANAGE_STATE, consult the VC++ online documentation.
HOWTO: Add MFC Support to an ATL Project

Q173974

uliser 2004-07-15
  • 打赏
  • 举报
回复
不是有支持选项吗?

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧