Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking disk usage 1

Status
Not open for further replies.

xenomage

Programmer
Jun 27, 2001
98
0
0
SG
Hi all,

it's there any functions that could actually check the disk usage in visual c++.

Any suggestion is welcome. Thanks.

xeno
 
I have used this to get disk space etc if thats what you mean by use

Code:
FARPROC pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
  unsigned hyper i64FreeBytesAvailable = 0;    // bytes available to caller
  unsigned hyper i64TotalNumberOfBytes = 0;    // bytes on disk
  unsigned hyper i64TotalNumberOfFreeBytes = 0;// free bytes on disk

  if(strcmp(Drive, "") != 0)
  {
    CString strDrive = "C:\\";
    nErrTrap = ::GetDiskFreeSpaceEx(strDrive,(PULARGE_INTEGER)&i64FreeBytesAvailable,
                     (PULARGE_INTEGER)&i64TotalNumberOfBytes, (PULARGE_INTEGER)&i64TotalNumberOfFreeBytes);
    if(!nErrTrap)
      lLastError = GetLastError();
  }
}

Go not to cats for advice for they will just walk over the keyboard
 
please ignore the
if(strcmp(Drive, "") != 0)
{
...
...
}
clause
its a code fragment from something else that I was doing


Go not to cats for advice for they will just walk over the keyboard
 
Hi snuv:

I couldn't follow the reason why you needed to check the proc address for the API in Visual C++. Please explain.

Thanks in advance.
Rahul
 
From MSDN:

"Windows 95 OSR2 and later: The GetDiskFreeSpaceEx function is available beginning with Windows 95 OEM Service Release 2 (OSR2). To determine whether GetDiskFreeSpaceEx is available, call GetModuleHandle to get the handle to Kernel32.dll. Then you can call GetProcAddress."
 
Yup

Code:
if (pGetDiskFreeSpaceEx)
{
...
}
else
{
  //use GetDiskFreeSpace
}
[\code]

GetDiskFreeSpace() has a limit of 2GB and overflows the values



Go not to cats for advice for they will just walk over the keyboard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top