Link to home
Start Free TrialLog in
Avatar of Ra
Ra

asked on

Displaying results from GetDiskFreeSpaceEx()

Hey guys, I'm using GetDiskFreeSpaceEx() to get the disk size and free space of whatever disk I select.  The function works perfectly and returns the correct size of the disk in bytes.

The problem I'm running into is that I want to display the data as kilobytes, megabytes, or gigabytes.  With 32-bit integers, I would just type cast them to double and divide by 1024 the necessary number of times.  But since GetDiskFreeSpaceEx() uses unsigned 64-bit integers, I get an error trying to type cast to double.  I tried doing a normal divide to get the integer portion of the result and then using the modulus operator (%) to get the remainder... but modulus doesn't seem to work correctly with such large numbers (and apparently chops of any leading zeros).

Is there a way to convert unsigned 64-bit integers to double?  If not, how can I display the bytes as KB, MB, or GB?

I'm using MS Visual C++ 6.0 on Windows NT.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of mnashadka
mnashadka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ra
Ra

ASKER

Thanks mnashadka, that worked.  I don't like type casting unsigned integers to signed ones due to possible corruption of data, but in this case I don't believe I'll ever encounter a drive that goes above the limit of a signed __int64.  Thanks for the help.
I agree with you about the signed/unsigned thing.  If you only need integers, not floating point numbers, you can using the unsigned __int64 instead.  I think it's called ULONGLONG or something like that.  Either way, I'm glad that I could help.  Good luck.

Mike