it seems to be working ,on my c:\ drive it returns 74. (not sure why it has a period) i take it out with strtrim
and windows displays it as 74.5gb
can anyone help with maybe getting it to return 74.5 like windows does, also would like the free space
.data?
szFileSysName db 256 dup(?)
lpFreeBytesAvailableToCaller dd ?
lpTotalNumberOfBytes dd ?
buffer db 256 dup(?)
outbuffer db 256 dup(?)
.code
start:
INVOKE GetVolumeInformation,CTEXT("C:\"),0,0,0,0,0,ADDR szFileSysName,MAX_PATH
invoke GetDiskFreeSpaceEx, CTEXT("C:\"),addr lpFreeBytesAvailableToCaller,addr lpTotalNumberOfBytes, 0
invoke StrFormatByteSize64, lpTotalNumberOfBytes, lpTotalNumberOfBytes+4, ADDR buffer, SIZEOF lpTotalNumberOfBytes
invoke StrTrim,addr buffer,CTEXT(".")
invoke lstrcat,addr buffer,CTEXT("GB")
invoke wsprintf,addr outbuffer,CTEXT("Disk Space: %s",13,10,"File System: %s"),addr buffer,addr szFileSysName
invoke MessageBox, NULL,addr outbuffer,CTEXT("C:\ Drive Info"), MB_OK
invoke ExitProcess,NULL
end start
Hi ChillyWilly:
Try CTXT NOT TEXT!
ie
INVOKE GetVolumeInformation,CTXT("C:\"),0,0,0,0,0,ADDR szFileSysName,MAX_PATH
Regards: herge
StrFormatByteSize64 will format the string as necessary. If the value is in the GB range then the string will be formatted as GB. Under Windows 2000 for my drive C I get:
User free space: 2.86 GB
Total capacity: 18.6 GB
Total free bytes: 2.86 GB
The values match those that Windows reports in the disk properties.
this is the macro, it shouldnt affect the output of StrFormatByteSize64
CTEXT MACRO y:VARARG
LOCAL sym, dummy
dummy EQU $;; MASM error fix
CONST segment
IFIDNI <y>,<>
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends
EXITM <OFFSET sym>
ENDM
this is what i get if i dont use strtrim
(http://img193.imageshack.us/img193/78/hddf.png)
.data?
szFileSysName db 256 dup(?)
lpFreeBytesAvailableToCaller dd ?,? ;GetDiskFreeSpaceEx expects this to be 64-bits
lpTotalNumberOfBytes dd ?,? ;GetDiskFreeSpaceEx expects this to be 64-bits
buffer db 256 dup(?)
outbuffer db 256 dup(?)
.code
start:
INVOKE GetVolumeInformation,CTEXT("C:\"),0,0,0,0,0,ADDR szFileSysName,MAX_PATH
invoke GetDiskFreeSpaceEx, CTEXT("C:\"),addr lpFreeBytesAvailableToCaller,addr lpTotalNumberOfBytes, 0
invoke StrFormatByteSize64, lpTotalNumberOfBytes, lpTotalNumberOfBytes+4, ADDR buffer, SIZEOF buffer ;not "SIZEOF lpTotalNumberOfBytes" - this was 4 bytes
invoke StrTrim,addr buffer,CTEXT(".")
invoke lstrcat,addr buffer,CTEXT("GB")
invoke wsprintf,addr outbuffer,CTEXT("Disk Space: %s",13,10,"File System: %s"),addr buffer,addr szFileSysName
invoke MessageBox, NULL,addr outbuffer,CTEXT("C:\ Drive Info"), MB_OK
invoke ExitProcess,NULL
end start
Here is a little horror I shot together while waiting for a backup to finish today. If you have a removable drive that has nothing in it when run from the command line it may ask you to put something in the drive. It displays the results in tabular form like as follows.
drv disk free
=== ==== ====
B:\ 4 gb 3 gb
C:\ 233 gb 224 gb
D:\ 227 gb 226 gb
E:\ 227 gb 218 gb
F:\ 244 gb 243 gb
G:\ 233 gb 229 gb
H:\ 233 gb 222 gb
I:\ 233 gb 226 gb
J:\ 233 gb 140 gb
K:\ 233 gb 233 gb
L:\ 233 gb 219 gb
M:\ 233 gb 229 gb
N:\ 233 gb 203 gb
O:\ --- ---
Z:\ 596 gb 233 gb
Press any key to continue ...
Asd a command line toy you would remove the "inkey" so it did not wait for a keypress.
You will note that Hutch is using GetDiskFreeSpaceEx to retrieve the information. This is very inportant for drives greater than 2gb as GetDiskFreeSpace will report erroneous values for such drives. There is other data returned by GetDiskFreeSpaceEx that may be nice to report, also.
Paul
@hutch how come GetDiskFreeSpaceExhas 4 parameters when msdn only has 3?
http://msdn.microsoft.com/en-us/library/aa364937(VS.85).aspx
i see 4
Willy,
The actual API passes a QWORD where the header in MASM32 makes that into 2 DWORDs. I coded the work around in much the same way that sinsi did, pushed the high and low DWORD of the 64 bit variable which puts the right data on the stack.
oops i meant msdn has 4 and the function has 5
@hutch ok , i still gotta learn 64 bit and qword
also is there a way to void the cf card error when its not in drive