2

per https://en.wikibooks.org/wiki/Windows_Programming/Handles_and_Data_Types#HANDLE,

HANDLEs are defined as being unsigned 32-bit quantities in windows.h

However, in WinDef.h, we see the following:

DECLARE_HANDLE            (HWND);

and in winnt.h, we see the following:

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct name##__ *name
#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif

This tells me that window handles are simple pointers. It seems to me this means that the max size of a window handle depends on the max size of addressable memory, which is 64 bits in most new machines. What am I missing?

sartoris
  • 816
  • 1
  • 7
  • 21
  • 6
    This text is very old, note the phrase "on modern 32-bit systems". This was written ~25 years ago. No, it behaves like a pointer (struct* and PVOID) so is a 64-bit type in a 64-bit program. It doesn't point to anything useful, handle values are intentionally opaque. – Hans Passant May 28 '19 at 16:05
  • Windows header file definition is, well, definitive – David Heffernan May 28 '19 at 16:25
  • 3
    HWNDs can be shared across process boundaries. So even though they are *implemented* as pointers, their *values* will not go outside of the 32bit range for interoperability with 32bit apps. See [What is the range of a Windows HANDLE on a 64 bits application?](https://stackoverflow.com/questions/18266626/) – Remy Lebeau May 28 '19 at 17:26
  • 1
    Thanks, @RemyLebeau - According to https://learn.microsoft.com/en-us/windows/desktop/WinProg64/interprocess-communication, converting from 32 to 64 bit handles involves sign-extending the value, so this means handles are NOT unsigned; but as Hans points out, they are not really integers either. I think I'm having an Aha! moment. – sartoris May 28 '19 at 18:06

0 Answers0