I've got an app A that launches a second app B and immediately terminates. I would like app B to wait on process A to finish before doing any work. In process B I'm currently calling GetWindowThreadProcessId() to retrieve the process id of A, then using OpenProcess() to obtain the process handle, and then calling WaitForSingleObject() to wait until the process has ended. The problem is that WaitForSingleObject() is returning WAIT_FAILED. What am I doing wrong?
Here is how I start the process:
memset (&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_FORCEOFFFEEDBACK;
bResult = CreateProcess (NULL,
And here is how I attempt to wait on the process in app B:
HWND hwnd = FindWindow (WINDOW_CLASS, WINDOW_NAME);
GetWindowThreadProcessId (hwnd, &nProcId);
HANDLE hProcess = OpenProcess (STANDARD_RIGHTS_REQUIRED, FALSE, nProcId);
DWORD dwWaitResult = WaitForSingleObject (hProcess, 5000);
Thanks for any help!