gpt4 book ai didi

c++ - 如何使用 winapi 等待非子进程?

转载 作者:行者123 更新时间:2023-11-30 01:11:48 25 4
gpt4 key购买 nike

我读了:

代码片段:

HANDLE  hProcess = OpenProcess(SYNCHRONIZE, TRUE, inProcessID); 

if (NULL == hProcess)
{
WaitForSingleObject(hProcess,INFINITE);
}

我已经尝试了 WaitForSingleObjectWaitForSingleObjectEx,实际上都没有在等待。

例如,假设记事本正在运行,我想等待它被某些用户关闭。我该怎么办 ?

最佳答案

来自 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) ...

关于c++ - 如何使用 winapi 等待非子进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35271993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com