WinExec() does not operate synchronously and will not wait until the called process is closed before returning to the calling application. Instead, it will return immediately and return a process handle indicating if the process was successfully created or not. To access the code returned by the application launched with WinExec(), you will need to use code similar to the following:
! error creating the process
The GetExitCodeProcess function retrieves the termination status of the specified process, and is defined in kerner32.dll. You will need to define it under a kernel32.dll entry within your module libraries. In ATEasy this function will be defined as:
GetExitCodeProcess(hProcess: Val AHandle, pdwCode : VAR DWord) : BOOL
A description of the function is provided below:
HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // termination status
- hProcess [in] - Handle to the process. For Windows NT/2000/XP, the handle must have PROCESS_QUERY_INFORMATION access. For more information, see Process Security and Access Rights.
- lpExitCode [out] - Pointer to a variable to receive the process termination status.
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:
If the specified process has not terminated, the termination status returned is STILL_ACTIVE. If the process has terminated, the termination status returned may be one of the following:
- 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.