The information in this article applies to:
SUMMARY
The processes for detecting program terminations fall into two categories:
MORE INFORMATIONWin32 processes can use one of the Wait functions to wait for a spawned process. By using CreateProcess() to launch a Win32 process, 16-bit process, or MS-DOS-based application, you can fill in a PROCESS_INFORMATION structure. The hProcess field of this structure can be used to wait until the spawned process terminates. For example, the following code spawns a process and waits for its termination:
If necessary, you can put this code into a separate thread to allow the
initial thread to continue to execute.
NOTE: For a discussion of how the NTVDM WOW architecture may influence waiting on 16-bit applications, please see the following article in the Microsoft Knowledge Base: Q105676 Starting and Terminating Windows-based ApplicationThis synchronization method is not available to 16-bit processes. Instead, they must use the TOOLHELP NotifyRegister function to register a callback function to be called when a program terminates. This method will detect the termination of 16-bit processes and MS-DOS-based applications, but not Win32 processes. The following code shows how to register a callback function with NotifyRegister():
The next section of code demonstrates the implementation of the callback
function:
The NotifyRegisterCallback() API is called by the 16-bit TOOLHELP DLL in
the context of the process that is causing the event. Problems arising
because of reentrancy and notification chaining makes the callback function
subject to certain restrictions. For example, operations that cause
TOOLHELP events cannot be done in the callback function. (See the TOOLHELP
NotifyRegister function documentation in your Software Development Kit for
events that cause TOOLHELP callbacks.)
There is no way a 16-bit process can be notified when a Win32 process exits. However, a 16-bit process can use TaskFirst() and TaskNext() to periodically walk the task list to determine if a Win32 process is still executing. This technique also works for 16-bit processes and MS-DOS-based applications. For example, the following code shows how to check for the existence of a process:
Refer to the TermWait sample for complete details on how to use
NotifyRegister and implement a callback function. For additional
information, please search in the Microsoft Knowledge Base using this word:
TERMWAIT Additional query words: end exit notification notify spawn terminate termination
Keywords : kbcode kbprg kbKernBase kbThread kbGrpKernBase |
Last Reviewed: January 14, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |