GetExitCodeProcess function
Applies to: desktop apps only
Retrieves the termination status of the specified process.
Syntax
BOOL WINAPI GetExitCodeProcess( __in HANDLE hProcess, __out LPDWORD lpExitCode );
Parameters
- hProcess [in]
-
A handle to the process.
The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right. For more information, see Process Security and Access Rights.
Windows Server 2003 and Windows XP: The handle must have the PROCESS_QUERY_INFORMATION access right. - lpExitCode [out]
-
A pointer to a variable to receive the process termination status. For more information, see Remarks.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
This function returns immediately. If the process has not terminated and the function succeeds, the status returned is STILL_ACTIVE. If the process has terminated and the function succeeds, the status returned is one of the following values:
- The exit value specified in the ExitProcess or TerminateProcess function.
- The return value from the main or WinMain function of the process.
- The exception value for an unhandled exception that caused the process to terminate.
Important The GetExitCodeProcess function returns a valid error code defined by the application only after the thread terminates. Therefore, an application should not use STILL_ACTIVE (259) as an error code. If a thread returns STILL_ACTIVE (259) as an error code, applications that test for this value could interpret it to mean that the thread is still running and continue to test for the completion of the thread after the thread has terminated, which could put the application into an infinite loop.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- ExitProcess
- ExitThread
- Process and Thread Functions
- Processes
- TerminateProcess
- Terminating a Process
- WinMain
Send comments about this topic to Microsoft
Build date: 3/7/2012
- 2/1/2012
- Maltese Falcon
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetExitCodeProcess(
[In] IntPtr ProcessHandle,
[Out] out int ExitCode
);
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetExitCodeProcess(ByVal processHandle As SafeProcessHandle, <Out> ByRef exitCode As Integer) As Boolean
End Function
The others are just special cases of calling ExitProcess (handy to know what value is passed of course):
The C Runtime Library calls ExitProcess when your main/WinMain function returns.
The default unhandled exception filter calls ExitProcess when an exception is unhandled.
- 3/11/2008
- Ben Voigt - old ID