Discussion:
Aborting a MFC program Problem
(too old to reply)
TPFGuru
2006-01-11 00:16:02 UTC
Permalink
I created my MFC app as SDI without doc/view support. The
CMyWindowFrame::OnCreate function creates the status and tool bars, and
returns -1 if a failure occurs. So, I decided to put my code here to also
return -1 if my app fails to create a DirectX device.

I am messing around with the device creation and actually caused it to fail,
but when my app returns -1 in the OnCreate function, I get an exception in a
MFC program (winocc.cpp):

BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));

if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}

It bombs on the last instruction, because m_pCtrlSite is 0xfeeefeee.

Now I wonder what would happen if it failed to create the status bar or
toolbar. Did I find a bug in MFC (no one ever tested the failure to create
the other resources)?

I tried to add the AfxAbort() command, but it is not very graceful either.

How can I make the program exit in this situation?

Thanks.
TPFGuru
2006-01-11 07:30:02 UTC
Permalink
I solved it. I found that the pFrame->LoadFrame call in my main app was not
checking the BOOL return code. I added a check to that, and it now works.
It was calling the ShowWindow() function next, which explains the error.
Post by TPFGuru
I created my MFC app as SDI without doc/view support. The
CMyWindowFrame::OnCreate function creates the status and tool bars, and
returns -1 if a failure occurs. So, I decided to put my code here to also
return -1 if my app fails to create a DirectX device.
I am messing around with the device creation and actually caused it to fail,
but when my app returns -1 in the OnCreate function, I get an exception in a
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
It bombs on the last instruction, because m_pCtrlSite is 0xfeeefeee.
Now I wonder what would happen if it failed to create the status bar or
toolbar. Did I find a bug in MFC (no one ever tested the failure to create
the other resources)?
I tried to add the AfxAbort() command, but it is not very graceful either.
How can I make the program exit in this situation?
Thanks.
e***@gmail.com
2014-04-27 23:52:11 UTC
Permalink
This is clearly a very old post, but could you explain a little bit more about how you solved the issue?

I'm trying to write an OpenGL application, and am in the unusual position where it works just fine on some machines but instantly throws the same exception you were getting on others.

My LoadFrame method looks like this:

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// base class does the real work

if (!CFrameWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
{
return FALSE;
}


// enable customization button for all user toolbars
BOOL bNameValid;
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);

for (int i = 0; i < iMaxUserToolbars; i ++)
{
CMFCToolBar* pUserToolbar = GetUserToolBarByIndex(i);
if (pUserToolbar != NULL)
{
pUserToolbar->EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
}
}

return TRUE;
}

...but in the instances where the 0xfeeefeee exception occurs, LoadFrame still returns true.

Thank you in advance for even looking at my code if you get the chance!
Post by TPFGuru
I solved it. I found that the pFrame->LoadFrame call in my main app was not
checking the BOOL return code. I added a check to that, and it now works.
It was calling the ShowWindow() function next, which explains the error.
Post by TPFGuru
I created my MFC app as SDI without doc/view support. The
CMyWindowFrame::OnCreate function creates the status and tool bars, and
returns -1 if a failure occurs. So, I decided to put my code here to also
return -1 if my app fails to create a DirectX device.
I am messing around with the device creation and actually caused it to fail,
but when my app returns -1 in the OnCreate function, I get an exception in a
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
It bombs on the last instruction, because m_pCtrlSite is 0xfeeefeee.
Now I wonder what would happen if it failed to create the status bar or
toolbar. Did I find a bug in MFC (no one ever tested the failure to create
the other resources)?
I tried to add the AfxAbort() command, but it is not very graceful either.
How can I make the program exit in this situation?
Thanks.
Continue reading on narkive:
Search results for 'Aborting a MFC program Problem' (Questions and Answers)
7
replies
A problem with C++ How a timer works?
started 2018-01-22 11:36:21 UTC
programming & design
Loading...