Best way to set exit code 
Author Message
 Best way to set exit code

What is the best way to set the exit code of a dialog based application. I
need the exit code to be 1 if the program is closed using the Ok button and
0 for the Cancel button.
It seems that I should use the ExitProcess() function but where and when
should it be called? I don't want to interfere with the orderly shut down of
the program.

Thanks
Chris



Sat, 10 Sep 2005 17:33:51 GMT  
 Best way to set exit code

Quote:
>What is the best way to set the exit code of a dialog based application.

Chris,

Handle ExitInstance.

Quote:
>need the exit code to be 1 if the program is closed using the Ok button and
>0 for the Cancel button.

The dialog is called from InitInstance, so I'd store a value in a
member variable of the CWinApp class as the return from the dialog's
DoModal, and return the value from ExitInstance.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sat, 10 Sep 2005 19:08:23 GMT  
 Best way to set exit code
Thanks
It seems to be working!
I am a little concerned that I could not find a example in the MFC help that
changed the value returned by ExitInstance(). This is what I did. Is this
correct?

int CInfoApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
CWinApp::ExitInstance();
return m_nExitCode;
//return CWinApp::ExitInstance();

Quote:
}



Quote:
> >What is the best way to set the exit code of a dialog based application.

> Chris,

> Handle ExitInstance.

> >need the exit code to be 1 if the program is closed using the Ok button
and
> >0 for the Cancel button.

> The dialog is called from InitInstance, so I'd store a value in a
> member variable of the CWinApp class as the return from the dialog's
> DoModal, and return the value from ExitInstance.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 11 Sep 2005 17:31:05 GMT  
 Best way to set exit code

Quote:
>I am a little concerned that I could not find a example in the MFC help that
>changed the value returned by ExitInstance(). This is what I did. Is this
>correct?

What you've done is what I had in mind Chris.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Sun, 11 Sep 2005 20:11:36 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with ideas, best ways etc...

2. Good ways to obfuscate/mangle strings?

3. are there better ways to read config file?

4. Any good ways to trace memory leaks?

5. DLL exiting with exit code 0x03

6. Diffrent ways of useing std::set or any template container

7. Ways to fill in missing code

8. exit(1), exit(2), exit(3) ....???

9. Application.Exit() (and a better data update strategy)

10. : How to set Cntrl+Q ot exit program and bind various other keys to functions

11. How to set code page from code?

12. convert the code of Arabic character set to code of Unicode

 

 
Powered by phpBB® Forum Software