We have a MFC dialog-based app which also supports COM automation. The MFC wizard which created it placed the following line in the "DlgProxy.cpp" file:
ASSERT (AfxGetApp()->m_pMainWnd != NULL);
The above line is in the CDlgProxy ctor, which seems to be a class used for automation support.
My problem is that when I run this application via OLE embedding, I get a failure on this line.
m_pMainWnd should be initialised in CMyApp::InitInstance() by the following code:
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
- but obviously the dialog is being created by some other class when the app is started by automation.
I have tried placing the following code in CMyAppDlg ctor:
// Set myself as the main window if not done already
if (theApp.m_pMainWnd == NULL)
theApp.m_pMainWnd = this;
However I still get the assertion.
What is the correct way to avoid this assertion?