what is 0xFFFFFFFF ?
I am learning from sample source code.
here is a part of the code :
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{ ....
what is 0xFFFFFFFF ?
I am learning from sample source code.
here is a part of the code :
dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{ ....
It's the same as -1, assuming dwFileSize is a (signed) double word.
The binary notation for 0xFFFFFFFF is: 1111 1111 1111 1111 1111 1111 1111 1111
The most significant bit (left-most bit) holds the sign; 1 for negative, 0 for positive.
You calculate the value of a negative number by inverting it and adding 1.
1111 1111 1111 1111 1111 1111 1111 1111
Inverting:
0000 0000 0000 0000 0000 0000 0000 0000
Adding 1:
0000 0000 0000 0000 0000 0000 0000 0001 = 1
So the value 0xFFFFFFFF is the same as -1
and,
with dwError = GetLastError() you can obtain what went wrong.
Regards,
Robert
It means the function failed.
0xFFFFFFFF is #define'd as
INVALID_HANDLE
INVALID_FILE_SIZE
TIME_ZONE_ID_INVALID
TLS_OUT_OF_INDEXES
ect
in winbase.h
not to mention
INFINITE
NMPWAIT_WAIT_FOREVER
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
then the binary notation for FFFFFFFF is also 1111 1111 1111 1111 1111 1111 1111 1111Originally posted by Monster
The binary notation for 0xFFFFFFFF is: 1111 1111 1111 1111 1111 1111 1111 1111
then what's the difference between them?
You need to put the 0x before it to tell the compiler it's a hexadecimal number:Originally posted by Kelvin
then the binary notation for FFFFFFFF is also 1111 1111 1111 1111 1111 1111 1111 1111
then what's the difference between them?
FFFFFFFF is not valid because the compiler thinks it's a decimal number, and F is not allowed in a decimal number.Code:int i = 10; /* decimal 10 */ int j = 0x10; /* decimal 16 */ int k = FFFFFFFF; /* invalid */
oic~
Thanks all ^^
Thanks your enthusiastic help
>>> if(dwFileSize != 0xFFFFFFFF)
That is actually poor style, you should use...
if(dwFileSize != INVALID_FILE_SIZE)
... the reason is that at some time, MS may decide to change the value of the return, but if they did so, they would also change the value of the named constant so your code would still work. I accept, of course, that it is unlikely in this case, however, using the raw value when a named constant has been specifically declared will cause you a problem one day.
You often find examples like this in MSDN - you'd have thought they for one would have known better.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
ThanksOriginally posted by adrianxw
>>> if(dwFileSize != 0xFFFFFFFF)
That is actually poor style, you should use...
if(dwFileSize != INVALID_FILE_SIZE)
... the reason is that at some time, MS may decide to change the value of the return, but if they did so, they would also change the value of the named constant so your code would still work. I accept, of course, that it is unlikely in this case, however, using the raw value when a named constant has been specifically declared will cause you a problem one day.
You often find examples like this in MSDN - you'd have thought they for one would have known better.
but where can I find error constant like "INVALID_FILE_SIZE"?
Check out your header files, these are near the top of Winbase.hCode:#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) #define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFF) #define INVALID_SET_FILE_POINTER ((DWORD)-1) #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
Thanks !
MSY2KOriginally posted by adrianxw
>>> if(dwFileSize != 0xFFFFFFFF)
That is actually poor style, you should use...
if(dwFileSize != INVALID_FILE_SIZE)
... the reason is that at some time, MS may decide to change the value of the return, but if they did so, they would also change the value of the named constant so your code would still work. I accept, of course, that it is unlikely in this case, however, using the raw value when a named constant has been specifically declared will cause you a problem one day.
You often find examples like this in MSDN - you'd have thought they for one would have known better.