Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Terminate an application

What is the best way to terminate an application? I usually just call exit(0); from within my view-class, but sometimes that generates an error message. Suggestions?



Comments

  • weiccoweicco Posts: 950Member
    : What is the best way to terminate an application? I usually just call exit(0); from within my view-class, but sometimes that generates an error message. Suggestions?
    :
    :
    :

    Hmm... I have used exit(1); and haven't got a single error. What does that number in exit argument mean? Has this something to do with this prob?

  • parbyparby Posts: 4Member
    : : What is the best way to terminate an application? I usually just call exit(0); from within my view-class, but sometimes that generates an error message. Suggestions?
    : :
    : :
    : :
    :
    : Hmm... I have used exit(1); and haven't got a single error. What does that number in exit argument mean? Has this something to do with this prob?
    :

    I don't think so. You should use exit(0); since that indicates EXIT_SUCCESS. exit(1) indicates EXIT_FAILURE.

    I think my problem is that i don't clean up after my application. I have an App-Wizard-generated SDI-application and when I call exit(0); there is an error message that says that a pagefault has occured in MFC42.dll. I have tried using static linking and the problem seems to go away, but that's not a good solution since my programsize increases almost 4 times with static linking. Has anyone experienced similar problems?


  • ColdShineColdShine Posts: 597Member
    Simply stop using the exit() function. It does work well for console programs, not for GUI ones. I don't use the MFC, but there will surely be a function (maybe named something like "AfxExit", "AfxExitProgram") which correctly ends the program.
    ________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]


  • Sephiroth2Sephiroth2 Posts: 423Member
    : : : What is the best way to terminate an application? I usually just call exit(0); from within my view-class, but sometimes that generates an error message. Suggestions?
    : : :
    : : :
    : : :
    : :
    : : Hmm... I have used exit(1); and haven't got a single error. What does that number in exit argument mean? Has this something to do with this prob?
    : :
    :
    : I don't think so. You should use exit(0); since that indicates EXIT_SUCCESS. exit(1) indicates EXIT_FAILURE.
    :
    : I think my problem is that i don't clean up after my application. I have an App-Wizard-generated SDI-application and when I call exit(0); there is an error message that says that a pagefault has occured in MFC42.dll. I have tried using static linking and the problem seems to go away, but that's not a good solution since my programsize increases almost 4 times with static linking. Has anyone experienced similar problems?
    :
    :
    Use PostQuitMessage(0) instead, or close the main window of the MFC application.

  • pingpongpingpong Posts: 937Member
    one way to do it is

    AfxGetMainWnd()->SendMessage(WM_CLOSE, 0, 0);

    : Simply stop using the exit() function. It does work well for console programs, not for GUI ones. I don't use the MFC, but there will surely be a function (maybe named something like "AfxExit", "AfxExitProgram") which correctly ends the program.
    : ________
    : [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]
    :
    :




  • pingpongpingpong Posts: 937Member
    or PostMessage.. logically better i suppose

    : one way to do it is
    :
    : AfxGetMainWnd()->SendMessage(WM_CLOSE, 0, 0);
    :
    : : Simply stop using the exit() function. It does work well for console programs, not for GUI ones. I don't use the MFC, but there will surely be a function (maybe named something like "AfxExit", "AfxExitProgram") which correctly ends the program.
    : : ________
    : : [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]
    : :
    : :
    :
    :
    :
    :


Sign In or Register to comment.