Windows API DuplicateHandle ()
http://msdn.microsoft.com/en-us/library/ms724251(VS.85).aspx
Requires duplication of the Object and a handle to both the source process and the other process in which you want to use the duplicated descriptor.
I assume that if I have two UNSPECIFIED processes, could I call DuplicateHandle () in one of them while I had available descriptors available?
My question is using Pipe to communicate between two processes to achieve this using an event.
In the first process, I CreateEvent (). Now I want to use WaitForSingleObject () in the second process.
If I try to duplicate the descriptor in the first process, will I need to first send the second descriptor of the process to the first process through the channel, duplicate the descriptor, and then send the descriptor to the second process?
Alternatively, I could start by sending the first process descriptor and the event descriptor to the second process and simply duplicate it there.
Is there a reason I should choose one after another?
To add wrinkle, the event descriptor is inherited from the parent process, which is actually called the first process (which is a CGI application). If this event descriptor was created using HANDLE_DO_NOT_DUPLICATE (something like this), can I actually use DuplicateHandle () to duplicate it for the second process?
Answer:
, NAMED , , DUPLICATE , , , , DuplicateHandle().
IPC. , DuplicateHandle() , .
hProcPseudo = GetCurrentProcess()
//Then call either:
lpRealHandle = OpenProcess( PROCESS_DUP_HANDLE, 0, hProcPseudo )
//This fails with GetLastError= 87 - The parameter is incorrect ???
// same thing with PROCESS_ALL_ACCESS ??
//OR
lRet = DuplicateHandle( hProcPseudo, hProcPseudo, hProcPseudo, lpRealHandle, DUPLICATE_SAME_ACCESS, 0, 0 )
//then I can Duplicate my Event Handle in the first thread with:
lRet = DuplicateHandle( hLocalProcess, hEvent, lpRealHandle, hDupEvent, DUPLICATE_SAME_ACCESS, 0, 0)
DuplicateHandle(), ,
hProcPseudo = 4294967295
hProcess = 152
.
( ) Duplicate handle:
DuplicateHandle( hFirstProcess, hEvent, hSecondProc, hDupEvent, DUPLICATE_SAME_ACCESS, 0, 0)
, :
DuplicateHandle hPipeFCGI GetLastError = 6 - .
( hFirstProcess) , hSecondProc !??
.