0

My question is about handles in the 64-bit Windows architecture: Can they be values larger than 2^32?

Handles in Visual Studio C/C++ are defined as pointers (64-bit): typedef void *HANDLE;

I read that at least some handles in 64-bit have only the lower 32 bits significant (https://msdn.microsoft.com/nl-nl/library/windows/desktop/aa384203(v=vs.85).aspx). But does that apply to ALL handles?

Second question is whether pointers to structs can be regarded as handles. Would it be safe to cast those to 32-bit integer?

Some background: I am porting a complex application to 64-bit and have to deal with in/out parameters that I would very much like to keep 32-bit integers. But they are sometimes (mis)used to transport handles and an occasional struct pointer too. I know that it would be better to separate them in different functions, but that would be very hard to do.

  • _"I read that"_ Where? What does the documentation say? – Lightness Races in Orbit Mar 31 '17 at 09:15
  • My question was marked as duplicate, and yes, I now see the other question. But the 2nd answer does not remove my worry that handles in some cases may not fit in a 32-bit integer. – André de Vries Mar 31 '17 at 09:45
  • That second answer is garbage; it just says "a colleague of mine insists". The first answer cites the official documentation with a formal declaration. What can be more trustworthy than that? – Lightness Races in Orbit Mar 31 '17 at 09:50
  • The linked MSDN article at the bottom of the 1st answer is fairly unambiguous. – Richard Critten Mar 31 '17 at 09:51
  • Thanks for the confirmation, I somehow needed that. – André de Vries Mar 31 '17 at 09:55
  • Hmmm, I just found this on MSDN, related to that second answer: "However, some items that Windows defines as handles are really just wrapped pointers (for example, HTREEITEM). These "handles" will be truncated if they are passed from a 64-bit process to a 32-bit process." https://msdn.microsoft.com/en-us/library/windows/desktop/ee872017(v=vs.85).aspx – André de Vries Mar 31 '17 at 10:01

0 Answers0