From: galapogos on
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?
From: Goran on
On May 31, 8:30 am, galapogos <gois...(a)gmail.com> wrote:
> 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)

That could be debugger showing a bad function. try stepping further in
with F11.
>
> 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?

Was there a change in the "Output" pane when you step over that
create? Normally, there is a line added when something fails.
Otherwise, put a breakpoint in CFrameWnd::Create and look there,
right?

Goran.
From: Woody on
Are you using rich edit controls? If so, you may have forgotten to
call AfxInitRichEdit. This is a common error.

See http://support.microsoft.com/kb/166132.
From: Joseph M. Newcomer on
Actually, you probably don't have "an" MFC application; you have an SDI, MDI or
dialog-based application, and if it is MDI or SDI, there is a view class from which your
view is derived (e.g., CFormView). As pointed out, adding a rich edit control without
doing initialization will kill you, but there are lots of other possibilities.
Nonetheless, without all this crticial information it is difficult to suggest approaches
that might help you find the error.
joe

On Sun, 30 May 2010 23:30:30 -0700 (PDT), galapogos <goister(a)gmail.com> wrote:

>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?
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm