Is it possible for a child process to inherit a handle from its parent process if one process is 32-bit and the other is 64-bit?
HANDLE is a 64 bit type on Win64 and a 32 bit type on Win32, which suggests that even it were supposed to be possible in all cases, there would be some cases where it would fail: a 64-bit parent process, a 32-bit child process, and a handle that can't be represented in 32 bits.
Or is naming the object the only way for a 32-bit process and a 64-bit process to get a handle for the same object?
If it is a file handle or other kernel handle, then yes.
It just happens that although HANDLE is a 64 bit type, it can always be converted to 32 bit and back for any valid handle value.
GDI handles cannot be inherited.
Yes, but when converting from 32-bit handles to 64-bit handles, make sure to sign-extend the value. That is, set bits 32-63 to the value of bit 31. So, 0x80000000
becomes 0xFFFFFFFF80000000
, not 0x0000000080000000
. Also, note that this compatibility between 32 and 64-bit handles is only guaranteed for user-mode handles (which is all you should ever be dealing with anyway unless you're writing a driver or some such thing that runs in kernel mode.)
See also: this SO question and its answer (What is Windows HANDLE range on a 64-bit application?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With