DWORD64 if set to -1 gives 32 1s i.e. 0xffffffffffffffffffffffffffffffff
Question
C++ code (Visual studio started with devenv /useenv (x64) and isWOW64 is false)
DWORD64 check;
check = -1;
printf("value %u", check);
it prints the value 4294967295 i.e. 0x(32)f which is the same if i do it with simple DWORD in an x32 environment
yes i know DWORD64 is unsigned __int64, but shouldn't it be 0x(64)f ?
what did the assembler do there ? disassembling the code didn't help me much.
Solution
You problem here lies in the printf
format string. Using %u
tells printf
to print a 32 bits value. Hence, it uses only the first 32 bits of your DWORD64
. To print all the 64 bits that has been pushed onto the stack, use %llu
(for unsigned long long
).
Note also that DWORD64
cannot be unsigned long
. On all Windows versions, even on Windows 64 bits, long
is 32 bits.
See LLP64 model.
OTHER TIPS
If you look at the manual page the %u
format specification is of type int
. This means that printf
reads the value as int
, which even on 64-bit platforms are still 32 bits.
Add a size specification of either ll
or I64
, so the format will be %I64u
.
It should be -1LL
because -1
is stored as a 32bit int