Process Exit Code

< BACK  NEXT >
[oR]

Each process has an exit code that can be accessed by other processes and can be used to indicate success or failure. A process sets an exit code in the value returned from either WinMain or the "C" main function. A process could, for example, return 0 to indicate success or a non-zero value indicating an error code.

An application can call the function GetExitCodeProcess to obtain theexit code for another application. This function is passed the process kernel object handle to the other process and a pointer to a DWORD to receive the exit code:

 DWORD dwExitCode; GetExitCodeProcess(hProcess, &dwExitCode); 

On return, dwExitCode will contain the exit code set by the application, or the value STILL_ACTIVE if the application has not yet terminated. So, you could call GetExitCodeProcess after WaitForSingleObject returns in Listing 5.3.

In Windows NT/98/2000 the ExitProcess function can be called at any time to terminate the application, and this function is passed the exit code for the application. However, this function is not available in Windows CE. You can call PostQuitMessage instead, but this will eventually terminate the message loop and then exit WinMain, and in doing so, set an exit code.

An application can terminate another application through calling the function TerminateProcess, and can pass a value to be used as the exit code for the application being terminated. However, as described in the section "Terminating a Process," it is best not to terminate applications using this function.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net