64位应用程序上的Windows HANDLE的范围是多少?

在WinAPI上,HANDLE类型定义为void *,因此在64位应用程序上,HANDLE值的范围可以为0到18446744073709551615。
但实际上是真的吗?任何文件是否指定了这样一个手柄的整体范围?

如果一个人希望将这个HANDLE存储在一个32位应用程序上的一个int32_t,这是完全正常的,但是在64位应用程序上,这个疑问就是这样。

MSDN声明:

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

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...