locked
Why my MFC program crashes so strangely? RRS feed

  • Question

  • Dear all,

    I wrote a MFC(New Feature Pack) program in Visual C++ 2008. However, the program crashes so strangely:

    1) Only the Release version crashes, Debug version never crashes.

    2) The program crashes when I start the program, before the appearance of the main window.

    3) On some PCs, the program crashes; on some other PCs, it doesn’t crash.

    4) On a same PC, when I login Windows XP with an account to run the program, it crashes. However, if I login with another account, it doesn’t crash. ( Both the accounts are administrators )

    5) On a same PC, I run the program, it crashes. If I copy the program to anther folder, it doesn’t crash.

    6) There is a error message box pops up when the program crashes:
    "TODO: <File description> has encountered a problem and needs to close. We are sorry for the inconvenience."

    Can anyone tell me the possible reasons? Thank you very much!!!

    Qiang

    Friday, December 25, 2009 2:46 PM

Answers

  • If the PCs it crashes on are on the same network as the development PC, it is time to set up remote debugging .

    You can also try to capture the dump files that are created (the ones that Dr. Watson wants to send to Microsoft every time a program crashes).  All you need to do is use the task manager to kill "drwin" when it is showing that dialog, then copy the .dmp file that it wants to send.  You can put the .dmp file back on your PC and open it in Visual Studio and get a good feel for what the program was doing when it crashed
    • Marked as answer by AddOil Sunday, December 27, 2009 3:55 PM
    Friday, December 25, 2009 5:55 PM

All replies

  • If the PCs it crashes on are on the same network as the development PC, it is time to set up remote debugging .

    You can also try to capture the dump files that are created (the ones that Dr. Watson wants to send to Microsoft every time a program crashes).  All you need to do is use the task manager to kill "drwin" when it is showing that dialog, then copy the .dmp file that it wants to send.  You can put the .dmp file back on your PC and open it in Visual Studio and get a good feel for what the program was doing when it crashed
    • Marked as answer by AddOil Sunday, December 27, 2009 3:55 PM
    Friday, December 25, 2009 5:55 PM
  • Thanks for your replay!

    I used MessageBox() to "debug" my program in release version. I found that my program crashed at "OnApplicationLook(theApp.m_nAppLook);" of the following function.

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
            return -1;

        BOOL bNameValid;
        // set the visual manager and style based on persisted value
        OnApplicationLook(theApp.m_nAppLook);

        ......
        ......
    }

    Any suggestion? Thank you very much!
    Saturday, December 26, 2009 7:45 AM
  • Thanks for your replay!

    I used MessageBox() to "debug" my program in release version. I found that my program crashed at "OnApplicationLook(theApp.m_nAppLook);" of the following function.

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
            return -1;

        BOOL bNameValid;
        // set the visual manager and style based on persisted value
        OnApplicationLook(theApp.m_nAppLook);

        ......
        ......
    }

    Any suggestion? Thank you very much!
    I do not see any message boxes in this code.

    What is OnApplicationLook()?

    What is m_nAppLook, and how is it initialized?

    Also, are you talking about your program crashing in Release mode, or about it crashing on other computers, or about running it outside Visual Studio?


    David Wilkinson | Visual C++ MVP
    Saturday, December 26, 2009 11:42 AM
  • Dear David,

    Thanks!

    OnApplicationLook() and m_nAppLook are generated by MFC Wizard(Visual C++ 2008 MFC Feature Pack).

    My program crashs when:

    (Release Version) && (On other computers) && (Outside Visual Studio)

    or

    (Release Version) && (On a same computers) && (Another windows login account) && (Outside Visual Studio)

    or

    (Release Version) && (On a same computer) && (Same windows login account) && (Copy to another folder) && (Outside Visual Studio)

    Thank you very much!

    Qiang
    Saturday, December 26, 2009 12:02 PM
  • I'm sorry, but I do not know anything about the Feature Pack. However, I believe you should be using VS2008 SP1, not VS2008 with Feature Pack.

    I would ask you again, how is m_nAppLook initialized?

    Does a new Wizard-generated application crash in this way (before you add any code).

    Many environment dependencies can be traced to invalid assumptions about the working directory. Your program should not make any assumptions about the location of the working directory.


    David Wilkinson | Visual C++ MVP
    • Edited by davewilk Saturday, December 26, 2009 12:43 PM (formatting)
    Saturday, December 26, 2009 12:42 PM