InitInstance gives a "Failed to create empty document" message
Hi,
I have an MFC application that was working, and I'm not sure what I
changed, but now in my InitInstance(), I get the above mentioned error
message, in the line:
if (!ProcessShellCommand(cmdInfo))
return FALSE;
And my program bombs out with the return FALSE; line.
After stepping into the functions, I find that it returns FALSE in the
following code segment in ProcessShellCommand()"
case CCommandLineInfo::FileNew:
if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
OnFileNew();
if (m_pMainWnd == NULL)
bResult = FALSE;
break;
OnFileNew() triggers the "Failed to create empty document" message.
Stepping into OnFileNew() and then into CDocManager::OnFileNew(), I
see that the call to pTemplate->OpenDocumentFile(NULL) triggers the
message. Stepping into that, I trace it to:
if (pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
delete pDocument; // explicit delete on error
return NULL;
}
which means the line "pFrame = CreateNewFrame(pDocument, NULL);" seems
to have created a null frame? I traced it into CreateNewFrame and
found that the conditional
if (!pFrame->LoadFrame(m_nIDResource,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, // default frame styles
NULL, &context))
succeeded and hence LoadFrame returned NULL(could not create a frame).
I traced it into LoadFrame and found that the conditional
if (!Create(lpszClass, strTitle, dwDefaultStyle, rectDefault,
pParentWnd, ATL_MAKEINTRESOURCE(nIDResource), 0L, pContext))
succeeded, and hence Create returned NULL. I tried to trace it into
Create() but it just brought me to the class CComPtrBase in
atlcomcli.h, to this code segment:
operator T*() const throw()
{
return p;
}
p at this point doesn't seem to be defined "(expression cannot be
evaluated" in the Autos window compared to defined values in the
working version)
I compared the parameters in Create() between the working and non-
working version and can't seem to figure out what's difference. What
does Create() failing mean and how can I solve it?
I've also compared cmdInfo prior to the ProcessShellCommand() call
between a working and non-working version in the Autos window and
could not find any difference between the 2.
Help please?