For an exercise, I look at the STARTUPINFO
structure. As you can see the last 3 elements has the type HANDLE
.
So I want to know which size HANDLE
has. Do somebody know 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With