user2346536
user2346536

Reputation: 1474

how to wait for a non-child process with winapi?

I read:

Code snippet:

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

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

I've tried WaitForSingleObject and WaitForSingleObjectEx, neither are actually waiting.

For example assume notepad is running and I want to wait for it to be closed by some user. What shall I do ?

Upvotes: 1

Views: 598

Answers (1)

0xFFFFFFFF
0xFFFFFFFF

Reputation: 852

From the documentation for 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.

So your if statement should be:

if (NULL != hProcess) ...

Upvotes: 5

Related Questions