1

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 ?

Community
  • 1
  • 1
user2346536
  • 1,464
  • 2
  • 21
  • 43
  • 1
    The code you provided looks correct (assuming you're opening the correct process via `OpenProcess`, and getting a valid `HANDLE`). What do you mean by "not working"? – lcs Feb 08 '16 at 14:29
  • 2
    When you look at `WaitForSingleObject` online document, it has a list shows all objects can be waited, which does not include Snapshot.... – 0xFFFFFFFF Feb 08 '16 at 16:34

1 Answers1

5

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) ...
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0xFFFFFFFF
  • 852
  • 5
  • 9