Click here to Skip to main content
15,902,931 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ16-Feb-05 10:46
LighthouseJ16-Feb-05 10:46 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ16-Feb-05 11:17
LighthouseJ16-Feb-05 11:17 
GeneralRe: Puzzling Runtime Error Pin
Steve Mayfield16-Feb-05 13:47
Steve Mayfield16-Feb-05 13:47 
GeneralRe: Puzzling Runtime Error Pin
Bob Ciora16-Feb-05 14:03
Bob Ciora16-Feb-05 14:03 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ16-Feb-05 14:26
LighthouseJ16-Feb-05 14:26 
GeneralRe: Puzzling Runtime Error Pin
Steve Mayfield16-Feb-05 14:52
Steve Mayfield16-Feb-05 14:52 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ16-Feb-05 15:04
LighthouseJ16-Feb-05 15:04 
GeneralRe: Puzzling Runtime Error Pin
Bob Ciora17-Feb-05 0:56
Bob Ciora17-Feb-05 0:56 
If you've rebuilt the application using AppWizard, you most likely don't need to call m_mainWnd::OnCmdMsg() (as you showed in your initial post). For most MFC apps, you don't have to write your own OnCmdMsg. Is there anything specific to m_mainWnd that requires you to do this?

When you quit the app with either the top right [x] or by double-clicking the top left icon, that generates a WM_CLOSE windows message. If you quit the app by selecting File->Exit, that generates an ID_APP_EXIT command, which is actually passed as the WPARAM of a WM_COMMAND windows message. WM_COMMAND messages are what are passed to OnCmdMsg, while the WM_CLOSE follows its own path.

So there are different code paths when you exit the app in those different ways. Does your m_mainWnd do something special in its OnCmdMsg when it sees the ID_APP_EXIT command? My suspicion on the whole thing is still that something is being invalidated/destroyed in m_mainWnd's OnCmdMsg, then the default CMainFrame::OnCmdMsg is trying to destroy the same thing, causing the crash.

In your OnCmdMsg handler, try adding a little "trap" at the beginning, something like this:
BOOL CMainFrame::OnCmdMsg( UINT nID, int nCode, void* pExtra,
                           AFX_CMDHANDLERINFO* pHandlerInfo)
{
  // ADD THIS:
  if( nID == ID_APP_EXIT )
  {
    int nDummy = 0;
  }

  // let the view have first crack at the command
  if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    return TRUE;

  // otherwise, do default handling
  return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
} 

You can then set a breakpoint on the "dummy" line (using F9) to trap the ID_APP_EXIT command when it's recieved. After that, you can single-step through the remainder of the function using F11 (this will step into functions) or F10 (to step over them).

I'd suggest stepping into your m_mainWnd::OnCmdMsg and see what it does when it gets this ID_APP_EXIT command.


Bob Ciora
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ17-Feb-05 4:01
LighthouseJ17-Feb-05 4:01 
GeneralRe: Puzzling Runtime Error Pin
Bob Ciora17-Feb-05 6:14
Bob Ciora17-Feb-05 6:14 
GeneralRe: Puzzling Runtime Error Pin
Bob Ciora17-Feb-05 6:29
Bob Ciora17-Feb-05 6:29 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ17-Feb-05 8:34
LighthouseJ17-Feb-05 8:34 
GeneralRe: Puzzling Runtime Error Pin
Bob Ciora18-Feb-05 2:35
Bob Ciora18-Feb-05 2:35 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ18-Feb-05 5:08
LighthouseJ18-Feb-05 5:08 
GeneralRe: Puzzling Runtime Error Pin
Ryan Binns16-Feb-05 17:45
Ryan Binns16-Feb-05 17:45 
GeneralRe: Puzzling Runtime Error Pin
LighthouseJ16-Feb-05 18:34
LighthouseJ16-Feb-05 18:34 
Questionhow to plot graph? Pin
gaurangjanodia16-Feb-05 8:17
gaurangjanodia16-Feb-05 8:17 
AnswerRe: how to plot graph? Pin
rocky_pulley16-Feb-05 8:22
rocky_pulley16-Feb-05 8:22 
AnswerRe: how to plot graph? Pin
Andrew Walker16-Feb-05 11:56
Andrew Walker16-Feb-05 11:56 
Questionsave options using registry or file? Pin
Mohammad Tarik16-Feb-05 8:17
Mohammad Tarik16-Feb-05 8:17 
AnswerRe: save options using registry or file? Pin
rocky_pulley16-Feb-05 8:26
rocky_pulley16-Feb-05 8:26 
AnswerRe: save options using registry or file? Pin
Ravi Bhavnani16-Feb-05 9:23
professionalRavi Bhavnani16-Feb-05 9:23 
AnswerRe: save options using registry or file? Pin
Mohammad Tarik16-Feb-05 9:49
Mohammad Tarik16-Feb-05 9:49 
AnswerRe: save options using registry or file? Pin
ThatsAlok16-Feb-05 18:00
ThatsAlok16-Feb-05 18:00 
GeneralBinary serial communications Pin
ed7115516-Feb-05 8:09
ed7115516-Feb-05 8:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.