What is the size of HANDLE? What is the size of HANDLE? windows windows

What is the size of HANDLE?


The Windows HANDLE type isn't a completely opaque type. Windows defines a couple of properties that you can depend on. The main one is the answer to your your question: it always of type void *. From the Windows Data Types entry on MSDN:

HANDLE

A handle to an object.

This type is declared in WinNT.h as follows:

typedef PVOID HANDLE;

Later on in the table you can see that PVOID is defined as void *.

So a HANDLE has the same size as void *. Or in other words, it's 32 bits when using a 32-bit compiler and 64 bits when using a 64-bit compiler. You shouldn't need to hard code either of these values in to your code, instead just use sizeof(HANDLE).

The other property of the Windows HANDLE type is very obscure, and is only barely documented: for kernel handles the bottom two bits are always zero. You shouldn't need to depend on this in your code, and hopefully you can see that you would never want to. I mention this for completeness and to emphasize how Microsoft has defined HANDLE to be more than just an internal implementation detail.


The best answer is to use sizeof(HANDLE) to get this information. If I remember correct, HANDLE is usually implemented as a typedef for void* and is therefore probably 32 or 64 bits, but you shouldn't rely on this.

Hope this helps!