The Windows API DuplicateHandle() http://msdn.microsoft.com/en-us/library/ms724251(VS.85).aspx Requires the Object handle to be duplicated and a handle to both the original
HANDLE
to the second process: hProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, dwProcessId);
DuplicateHandle(GetCurrentProcess(), hEvent, hProcess, &hDupEvent, 0, FALSE, DUPLICATE_SAME_ACCESS);
OpenProcess
eventually (I don't know what difference it would make, but you're supposed to...). Also, release BOTH handles to the event: the one given to the second process and the initial handle.Use a named pipe or mailslots for IPC, this should work reliably for your purpose. If you need to wait, use named wait handles.
Otherwise, I'd choose to do DuplicateHandle in the second process in order to set the handle ownership correctly.
Process Handle is different from process id. OpenProcess takes process id. Use something like...
HANDLE hProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId());
If I understood correctly, you want to synchronize two unrelated processes through the same event. If so, you can use named events.
Create one using CreateEvent API function, provide it a name, then from the second process use OpenEvent API function, specifying the name of the event.
You have similar functions for other synchronization objects, such as mutexes (OpenMutex) or semaphores (OpenSemaphore).