CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2008
    Posts
    13

    Crash while using CToolbar

    In my application, I am using a CToolbar object to create two buttons.One button launches a calculator and the other one is an exit button to exit the application.

    When clicking on the calculator button, the calc launches fine, however,when I click on the exit button, the application crashes.

    Both of them load on the application init, so I believe there is no issue with the loading of the toolbar itself.....

    Any Help regarding this....

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Crash while using CToolbar

    Without knowing what the crash is about, it's virtually impossible to help you. What kind of error do you get and what does the debugger show you during the crash ?

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Crash while using CToolbar

    What do your command handlers look like ?

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Crash while using CToolbar

    I suggest step by step debugging, http://www.codeguru.com/forum/showthread.php?t=360659.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Sep 2008
    Posts
    13

    Re: Crash while using CToolbar

    The exception I get is an access violation ( 0x0000005) in MFC42.dll.
    I believe it is because of some pointer becoming NULL and me trying to access it.

    The PreTranslateMessage(...) does not get the message, but through the child windows, it reaches the OnCommand() function.

    This is where I destroy the window and it seems like the message gets relayed back to the child windows and they crash....


    Is there a way I can make sure that the message does not get relayed back...
    since this is a window close event, can I write some code in the OnCommand() function itself that will make sure that my window gets completely destroyed and there is no message relayed back....

  6. #6
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Crash while using CToolbar

    I think you should try to fix the problem with accessing a NULL pointer. Check the pointers for validity. And if the pointer is NULL and is not supposed to be NULL, then try to figure why it's NULL and fix that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  7. #7
    Join Date
    Sep 2008
    Posts
    13

    Re: Crash while using CToolbar

    hmmm...
    @cilu : you are right.

    can you guide me with this help.

    There is a window..and there is my toolbar on the window....

    as soon as I click on the toolbar, how do I make sure that my window is notified of the event....

    ON_BN_CLICKED does not seem to help,

    It still goes into PreTranslateMessage with a mouse move event and then gets into the OnCommand(...) function in the parent window that a command has been executed.

    So, when it returns from this function that the Command has been handled, the child windows have already been destroyed ( since the button is a exit button, I have written code to destroy everything), hence resulting in the crash...

    The approach I was trying to look at it something like

    As soon as I click on a button in the toolbar, handle the event here itself,
    do not let the child windows know of it....

    What should I do to achieve this??

  8. #8
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Crash while using CToolbar

    Please post the code of the command handlers. Ideally, please post a compilable project that has just enough code to reproduce the error. Why are you destroying windows ? Did you create them yourself in the first place ?

  9. #9
    Join Date
    Sep 2008
    Posts
    13

    Re: Crash while using CToolbar

    I have found the reason why it was happening....
    It was because the command that the exit icon was being clicked was being relayed to the CDialog I have created by the components inside it.....but I was destroying these components before the message was relayed back.....

    Instead of destroying instantly, I am now using CDialog::EndDialog(TRUE) to set a flag to destroy the components after the message was relayed back to the components which sent the command handler to my CDialog derived object.....

    http://msdn.microsoft.com/en-us/libr...tw(VS.80).aspx

  10. #10
    Join Date
    Sep 2008
    Posts
    13

    Re: Crash while using CToolbar

    Thanks a lot for the help guys......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured