但实际上是真的吗?任何文件是否指定了这样一个手柄的整体范围?
如果一个人希望将这个HANDLE存储在一个32位应用程序上的一个int32_t,这是完全正常的,但是在64位应用程序上,这个疑问就是这样。
64-bit versions of Windows use 32-bit handles for interoperability.
When sharing a handle between 32-bit and 64-bit applications,only the
lower 32 bits are significant,so it is safe to truncate the handle
(when passing it from 64-bit to 32-bit) or sign-extend the handle
(when passing it from 32-bit to 64-bit). Handles that can be shared
include handles to user objects such as windows (HWND),handles to GDI
objects such as pens and brushes (HBRUSH and HPEN),and handles to
named objects such as mutexes,semaphores,and file handles.
The proper way to share such handles across process boundaries is by
zero-extending 32 bits handles to 64 bits,or vice versa by truncating
64 bits handles to 32 bits discarding the top bits.
请注意“句号扩展”句柄与“零延伸”句柄之间的区别。
编辑:从对这个问题的删除答案中的讨论来看,我认为扩展一个32位句柄来达到64位句柄而不是零扩展的意义在于保留对INVALID_HANDLE_VALUE的适当处理一个句柄的值。
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384203%28v=vs.85%29.aspx