Merging an MFC project into an ATL one.
I have a problem and am totally stuck. I have a project where ATL is
used (non-console application, using ATL dialogue elements) and I try
to add MFC support. Since Visual Studio (2005) doesn't provide func-
tionality for this, I am currently trying this on the source level. I
included the header files necessary, told the linker to include MFC
as shared dll and it compiles.
But when I tried to create a MFC CFrameWnd, I got an
AfxGetResourceHandle() assertion failure on LoadFrame(), because he
fails to load the menu bar resource, see
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2178326&df=100&fr=685.5&msg=2178326
The kind fellow who already helped me a lot there, told me that I
first have to create a CWinApp object and to call AfxInitialize() and
/or AfxWinInit() to correctly initialize the application to be able
to use MFC windows in it.
So the problem seems to be that currently the main event loop is
realized by invokation of the WinMain() member of CAtlExeModuleT via
the _tWinMain() function (see code extract below).
When I invoke InitInstance() on the CWinApp object I get a second
event loop in addition to _tWinMain(), right? So how do I get one
event loop for the ATL and the MFC stuff together to add MFC support
to my project?
I found the following:
http://support.microsoft.com/?scid=kb%3Ben-us%3B173974&x=14&y=9
in the InitInstance() function a CWnd is created and CreateEx() invo-
ked on it. But my main window is an ATL one (type CAxDialogImpl<>,
see code below) and CWnd and CAxDialogImpl aren't compatible, aren't
they? I really would like to not change the type of my main window
since it contains many COMMAND_HANDLER() functions and uses event
sinks (COM stuff) to realize its functionality.
Is there a way to keep it as the "main (dialog) window" of my appli-
cation?
It would be so great if anyone could help me here, because I don't
know what else to try.
So I hope someone could answer and send you
best regards,
Peter.
Here comes the code:
// 1.) Instantiating CWinApp here...
// 2.) Putting the "if (!theMFCApp.PreTranslateMessage(&msg))" here? or
// in _tWinMain() ? When not in _tWinMain(), do I get two main event
// loops then (which I don't want)? Should I substitute the
// _AtlModule.WinMain(nShowCmd) then? If yes, how?
//Here comes the code I started from:
class CSampleModule : public CAtlExeModuleT< CSampleModule >
{
public :
HRESULT PreMessageLoop(int nShowCmd)
{
HRESULT hr = CAtlExeModuleT::PreMessageLoop(nShowCmd);
if (FAILED(hr))
return hr;
CMainDialog mainDlg;//CMainDialog is a subclass of CAxDialogImpl<>
mainDlg.DoModal();
return S_FALSE;
}
};
CSampleModule _AtlModule;
//
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
{
return _AtlModule.WinMain(nShowCmd);
}

