I am having TONS of trouble using GetDiskFreeSpaceEx in my project.

It ALWAYS returns the same value, no matter what I do.
Can anyone please point me to an example of someone
actually having used this in MASM before?

Been going mad over this thing for more than 2 weeks now.
Posted on 2004-08-06 04:21:59 by The Beginner
Posted on 2004-08-06 04:47:23 by Vortex
That is the problem... I know about the MSDN on the function, but I cannot
get it to work in MASM.
Posted on 2004-08-06 04:59:41 by The Beginner

invoke GetDiskFreeSpaceEx, addr cDrive, addr AvailableToCaller, addr TotalBytesUsed, addr TotalBytesAvail
invoke dwtoa, addr TotalBytesAvail, addr dBuffer
;invoke wsprintf, addr dBuffer, CStr("%ld.%ld"), addr TotalBytesAvail

invoke GetDlgItem, hWind, IDC_CBO1
mov hCombo, eax

invoke SendMessage, hCombo, CB_ADDSTRING, 0, addr dBuffer
invoke SendMessage, hCombo, CB_SETCURSEL, 0, 0

What am I doing wrong with this? I am trying to display the total size of any given hard drive in the format: 20.0GB or what ever size it may be.

I come from *gasp* Delphi and am trying to learn a little bit of MASM just because I like to tinker.
In Delphi, I can use:

DriveFree := FloatToStrF(DiskSize(s)/ 1048576, ffFixed,10,2);
//DriveFree is a buffer

to get the disk size to display the way I want. What would be the equivalent in MASM syntax?

Can anyone help me here? This thing is really driving me up the walls. :)

Thanks again in advance,
The Beginner
Posted on 2004-08-11 07:26:15 by The Beginner
GetDiskFreeSpaceEx returns a 64 bit number.

dwtoa is looking at only "half" of the number...
Posted on 2004-08-11 11:16:33 by S/390

GetDiskFreeSpaceEx returns a 64 bit number.

dwtoa is looking at only "half" of the number...

Do you have any suggestions then? Obviously it is beyond what I know
about this language.

Just trying to learn, hehe.... sometimes, need a little nudge in the right
direction. I know GetFreeDiskSpaceEx returns a 64-bit number, but I
am looking for a way to deal with it and display it properly.
Posted on 2004-08-11 20:18:15 by The Beginner
Since GetDiskFreeSpaceEx is obviously some sort of monster that everyone likes to avoid, can anyone tell me any other way to get the total size of a hard drive in MASM? Maybe an online tutorial, some documents (which I am having a hard time tracking down) of some kind? Anything?

Thanks again for at least trying to help, folks. I appreciate it.
Posted on 2004-08-12 15:44:07 by The Beginner
Just wanted to thank everyone for trying to help me sort this out. Guess it is too much trouble to implement GetDiskFreeSpaceEx, so no one really does it.

Thanks again all.
Posted on 2004-08-13 08:53:41 by The Beginner
Hi, I took the time to write a small example. This program gets the Disk Free and Disk Size of the current directory, and prints the information in a MessageBox.

The easiest way to work with 64bit integers is probably to use the FPU - so that's what I did. My code is fairly sucky and totally unoptimized, but seems to do the job. Oh yes, FPU treats int64 numbers as signed, so this code will give weird values for "insanely large" drives :-)

The printing code is flawed - a value like "1.02" will be printed as "1.2"...
Posted on 2004-08-13 11:23:26 by f0dder
f0dder, thank you very much for going through the trouble.

Now I will kick it around and try to learn what you did. A lot
of the code you wrote is new to me, hehe. Heck, I am still new
to this assembly/MASM stuff, so it's been slow going.

Again, thank you.
Posted on 2004-08-14 03:06:21 by The Beginner
No problem, Beginner - I needed to play a bit with floating-point anyway. Darn I hate writing FPU code, I'm not used to thinking in the stack-based manner, and the instruction set feels weird :)

Btw, there's a float-to-string conversion routine in the masm32 package, you might want to check that out (since mine is obviously bonk ;) ).
Posted on 2004-08-14 09:17:05 by f0dder
If you want some non-FPU code, here's a routine to convert 64bit to ASCII. It uses a trick of dividing the number by 1000000000, then converting the two halves to ASCII. So it doesn't cover the full range of a 64bit number, but it does handle numbers between 0 and 4,294,967,295,999,999,999.

It also inserts commas in the result string.

Posted on 2004-08-14 22:03:02 by S/390