Discussion:
Problem with GetDiskFreeSpaceEx
(too old to reply)
Deli
2005-04-23 14:26:50 UTC
Permalink
Hi,
I know that this group is about VB, but I can't find any group about winapi
only (or C winapi).
I use GetDiskFreeSpaceEx function to retrieve the info about disk space.
I have problem with TotalNumberOfBytes argument, because for larger
partitions the returned value is approximately 2 times bigger than the real
size.
Here's the code:

TCHAR buf[30] ;
ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes,
TotalNumberOfFreeBytes ;
GetDiskFreeSpaceEx(buf, &FreeBytesAvailable, &TotalNumberOfBytes,
&TotalNumberOfFreeBytes) ;
wsprintf(buf, "%u%u", TotalNumberOfBytes.HighPart,
TotalNumberOfBytes.LowPart) ;


Thanks for any help.
Randy Birch
2005-04-23 14:42:49 UTC
Permalink
I believe the group is called "SDK".
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



"Deli" <R0xD(qryv_)@op.pl> wrote in message news:d4dlqi$ep5$***@news.onet.pl...
: Hi,
: I know that this group is about VB, but I can't find any group about
winapi
: only (or C winapi).
: I use GetDiskFreeSpaceEx function to retrieve the info about disk space.
: I have problem with TotalNumberOfBytes argument, because for larger
: partitions the returned value is approximately 2 times bigger than the
real
: size.
: Here's the code:
:
: TCHAR buf[30] ;
: ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes,
: TotalNumberOfFreeBytes ;
: GetDiskFreeSpaceEx(buf, &FreeBytesAvailable, &TotalNumberOfBytes,
: &TotalNumberOfFreeBytes) ;
: wsprintf(buf, "%u%u", TotalNumberOfBytes.HighPart,
: TotalNumberOfBytes.LowPart) ;
:
:
: Thanks for any help.
:
Thorsten Albers
2005-04-23 14:45:08 UTC
Permalink
Post by Deli
I know that this group is about VB, but I can't find any group about winapi
only (or C winapi).
And what about microsoft.public.vc?
At least it is placed better there than in this group!
--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------
Rick Rothstein
2005-04-23 14:47:13 UTC
Permalink
Post by Deli
I know that this group is about VB, but I can't find any group about winapi
only (or C winapi).
I use GetDiskFreeSpaceEx function to retrieve the info about disk space.
I have problem with TotalNumberOfBytes argument, because for larger
partitions the returned value is approximately 2 times bigger than the real
size.
TCHAR buf[30] ;
ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes,
TotalNumberOfFreeBytes ;
GetDiskFreeSpaceEx(buf, &FreeBytesAvailable, &TotalNumberOfBytes,
&TotalNumberOfFreeBytes) ;
wsprintf(buf, "%u%u", TotalNumberOfBytes.HighPart,
TotalNumberOfBytes.LowPart) ;
Not sure if this will help you or not, but the following works for me in
VB. Note that Currency is a data type in VB defined as follows:

Currency variables are stored as 64-bit (8-byte) numbers in
an integer format, scaled by 10,000 to give a fixed-point
number with 15 digits to the left of the decimal point and 4
digits to the right. This representation provides a range of
-922,337,203,685,477.5808 to 922,337,203,685,477.5807.

Long is also a data type that is a signed 4-byte Integer with a range
of -2,147,483,648 to 2,147,483,647. The apostrophe is used to place a
comment in the code. Format is a VB function probably equivalent in some
way to your wsprintf function. Finally, the space followed by a
underscore character allows a single VB statement to continue across
multiple lines. Oh, and in VB, we have to declare the API functions as
shown (although the use of line continuations is arbitrary and
represents the way I like to present them).

Rick - MVP

Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long

Private Sub Form_Load()
Dim r As Long
Dim BytesFreeToCalller As Currency
Dim TotalBytes As Currency
Dim TotalFreeBytes As Currency
Dim TotalBytesUsed As Currency

' The drive to find
Const RootPathName = "C:\"
' Get the drive's disk parameters
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, _
TotalBytes, TotalFreeBytes)
' Show the results, multiplying the returned
' value by 10000 to adjust for the 4 decimal
' places that the currency data type returns.
Me.AutoRedraw = True
Me.Cls
Me.Print "Total Number Of Bytes:", _
Format$(TotalBytes * 10000, _
"###,###,###,##0") & " bytes"
Me.Print "Total Free Bytes:", _
Format$(TotalFreeBytes * 10000, _
"###,###,###,##0") & " bytes"
Me.Print "Free Bytes Available:", _
Format$(BytesFreeToCalller * 10000, _
"###,###,###,##0") & " bytes"
Me.Print "Total Space Used :", _
Format$((TotalBytes - TotalFreeBytes) * 10000, _
"###,###,###,##0") & " bytes"
End Sub
Mike D Sutton
2005-04-23 14:53:03 UTC
Permalink
Post by Deli
I know that this group is about VB, but I can't find any group about winapi
only (or C winapi).
I use GetDiskFreeSpaceEx function to retrieve the info about disk space.
I have problem with TotalNumberOfBytes argument, because for larger
partitions the returned value is approximately 2 times bigger than the real
size.
<code snipped>

Have a look at this page on the MSDN for example C++ code for the function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getdiskfreespaceex.asp
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://EDais.mvps.org/
Sam Hobbs
2005-04-26 01:42:24 UTC
Permalink
Post by Deli
Hi,
I know that this group is about VB, but I can't find any group about winapi
only (or C winapi).
I use GetDiskFreeSpaceEx function to retrieve the info about disk space.
I would first search the MSDN for sample code before asking for help. The KB
is part of the MSDN and often the KB has useful sample code. If there is not
a useful sample there, I would search the sample code. Many times the
Platform SDK and other samples provided with VC have sample code that is not
in the rest of the MSDN (at least not in earlier versions of the MSDN). If I
don't find a sample that way, I often search the newsgroups for sample code.
Finally, you can search the World Wide Web for samples. I assume you know
how to search the World Wide Web.

There are many newsroups beginning with

microsoft.public.platformsdk

such as:

microsoft.public.platformsdk.base

Loading...