Post by R.Wieser
Post by JJ
Works fine when duplicating the process handle.
Which exactly is the whole problem. How do you do that ? With
DuplicateHandle ? If so, how ? I cannot get it to work that way.
For the source process:
GetCurrentProcess(), &hCurrentProcess, PROCESS_DUP_HANDLE, TRUE, 0);
For the target process:
DuplicateHandle(hCurrentProcess, hDestProcess, hDestProcess,
&hDestProcess2, PROCESS_DUP_HANDLE, TRUE, 0);
OpenProcess(PROCESS_DUP_HANDLE, true, dwDestPID);
Post by R.Wieser
One at the senders side to convert the 'GetCurrentProcess' pseudo handle
into a real one - which than gets, together with the 'CreateFileMapping'
handle, send to the other side.
And the other side which uses both of the above in another 'DuplicateHandle'
to generate a memory-mapping handle thats valid in its own address space.
(this is where the "invalid handle" error is returned).
.... At least, that is what I think should be done, but for which I have not
been able to find any example (MSDN or otherwise).
And to be honest, I currently even start to doubt if the conversion from a
pseudo process handle to a real one returns one thats valid in another
By the way, I rewrote (as a test!) the whole thing to send the process ID,
and have the other side use an 'OpenProcess' with the PROCESS_DUP_HANDLE
flag, and that worked (the resulting process handle together with the
filemapping handle generated a handle that I could use with MapViewOfFile).
In other words, a
doesn't work, but a
I imagine that it has something to do with the DUPLICATE_SAME_ACCESS option
I'm using, but have not been able to find any kind of info telling me
anything else about it - and even less about (the usage of) the
dwDesiredAccess field. And without such info I'm up the creek without a
Duplicating the file mapping handle works fine too. i.e.
DuplicateHandle(hCurrentProcess, hFileMapping, hDestProcess,
&hFileMappingDestProcess, 0, TRUE, DUPLICATE_SAME_ACCESS);
Please keep in mind that duplicated handles for a remote process will only
be valid for that remote process. i.e. those handle values are valid only on
that remote process' context. So, don't use those handles from the process
that duplicate the handles.
Once the destination process' file mapping handle is created, you'll have to
let the destination process know the value of that handle. In the
destination process, use the value as a handle. i.e. as is. Typecast it if
necessary. Then pass it to MapViewOfFile().
During my test, ironically, I had to use window message to pass the handle
value to the destination process. All those IPC setup... For a mere 4 bytes
of data transfer. Now I'm feeling your frustration. :(