如何使用 winapi 等待非子进程?
how to wait for a non-child process with winapi?
我阅读了:
- How to wait for a process to finish C++
- How to use win32 CreateProcess function to wait until the child done to write to file
代码片段:
HANDLE hProcess = OpenProcess(SYNCHRONIZE, TRUE, inProcessID);
if (NULL == hProcess)
{
WaitForSingleObject(hProcess,INFINITE);
}
我试过 WaitForSingleObject
和 WaitForSingleObjectEx
,实际上都没有在等待。
例如,假设记事本是 运行,我想等待它被某些用户关闭。我该怎么办 ?
来自 OpenProcess
的文档:
If the function succeeds, the return value is an open handle to the
specified process.
If the function fails, the return value is NULL. To get extended error
information, call GetLastError.
所以你的 if 语句应该是:
if (NULL != hProcess) ...
我阅读了:
- How to wait for a process to finish C++
- How to use win32 CreateProcess function to wait until the child done to write to file
代码片段:
HANDLE hProcess = OpenProcess(SYNCHRONIZE, TRUE, inProcessID);
if (NULL == hProcess)
{
WaitForSingleObject(hProcess,INFINITE);
}
我试过 WaitForSingleObject
和 WaitForSingleObjectEx
,实际上都没有在等待。
例如,假设记事本是 运行,我想等待它被某些用户关闭。我该怎么办 ?
来自 OpenProcess
的文档:
If the function succeeds, the return value is an open handle to the specified process.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
所以你的 if 语句应该是:
if (NULL != hProcess) ...