GetExitCodeProcess
Description
Syntax
BOOL GetExitCodeProcess( HANDLE hProcess, LPDWORD lpExitCode )
Parameters
- hProcess
- [input] A handle to the process.
- lpExitCode
- [output] A pointer to a variable to receive the process termination status. For more information, see Remarks.
Return
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.
Examples
EX1
void create_and_terminate_process()
{
STARTUPINFO sinfo;
PROCESS_INFORMATION pinfo;
memset(&sinfo, 0, sizeof(STARTUPINFO));
memset(&pinfo, 0, sizeof(PROCESS_INFORMATION));
// test control wShowWindow
sinfo.dwFlags = STARTF_USESHOWWINDOW;
sinfo.wShowWindow = SW_SHOWMAXIMIZED;
BOOL bSucess = CreateProcess("C:\\Windows\\notepad.exe", NULL, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &sinfo, &pinfo);
DWORD dwCode;
if(GetExitCodeProcess(pinfo.hProcess, &dwCode))
{
if(dwCode == STATUS_PENDING)
out_str("still alive");
else
printf("code = %X\n", dwCode);
}
else
out_str("Failed to get exit code");
//wait 1 sec
LT_execute("sec -p 1");
TerminateProcess(pinfo.hProcess, 2);
if(GetExitCodeProcess(pinfo.hProcess, &dwCode))
printf("After terminated, code = %X\n", dwCode);
else
out_str("Failed to get exit code");
}
Remark
Retrieves the termination status of the specified process.
This function returns immediately.
If the process has not terminated and the function succeeds, the status returned is STATUS_PENDING.
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.
See Also
CreateProcess, TerminateProcess , ShellExecute, WinExec
header to Included
origin.h
Reference
|