Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
__int64 FileSizeDistance = 2711617536;

LARGE_INTEGER liSize;

liSize.LowPart = (int)(FileSizeDistance & 0xFFFFFFFF);
liSize.HighPart = (int)(FileSizeDistance >> 32);

_tprintf("LowPart:%d, HighPart:%d\n", liSize.LowPart, liSize.HighPart);

return 0;



The result is :

LowPart: -1583349760, HighPart: 0

What is the right way?
Posted
Updated 7-Jul-13 20:49pm
v2

I see that your compiler has support for 64bit signed integers. So you need to use the QuadPart member to store the value.

C++
LARGE_INTEGER liSize;
liSize.QuadPart = FileSizeDistance;


See MSDN[^] for details.

Good Luck!
 
Share this answer
 
The simplest would be
C++
liSize.QuadPart = FileSizeDistance;

Your assignment is not wrong, but the castings should be according to the desitination type (DWORD for LowPart and LONG for HighPart). Even your print output is correct. To get the expected output, just print the low part as unsigned:
_tprintf("LowPart:%u, HighPart:%d\n", liSize.LowPart, liSize.HighPart);
 
Share this answer
 
Comments
nv3 8-Jul-13 3:23am    
You beat my by a couple minutes Jochen :-)
Your value has been correctly loaded into liSize, although you could have done it an easier way, as solution 1 demonstrates. The problem in your code is the print out part. You used %d for the low order part LowPart, which is however an unsigned int. If you use %u instead you will receive the correct result. And it is correct that the high part is 0.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900