Currently viewing: GipsySoft » Front Page» Articles

RealGetDiskFreeSpace

Get the free disk space. GetFreeDiskSpaceEx is not available on Win95 and any programs written to use it must dynamically load the function. RealGetDiskFreeSpace does this, calling the correct function for the correct OS.

This function uses class CLoadLibray.

Tested in UNICODE.

__int64 RealGetDiskFreeSpace( LPCTSTR pcszPath );

Return value

Returns the number of bytes free on the drive specified.

Example


#include "stdafx.h"
#include <stdio.h>
#include <TCHAR.H>
extern __int64 RealGetDiskFreeSpace( LPCTSTR pcszPath );


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  LPCTSTR pcszDrive = _T("c:");
  __int64 i64 = RealGetDiskFreeSpace( pcszDrive );

  TCHAR szBuffer[ 256 ];
  const long lKB = (long)( i64 / 1024 );
  const long lMB = (long)( i64 / (1024 * 1024) );
  wsprintf( szBuffer, _T("drive %s has %dKB or %dMB free")
    , pcszDrive
    , lKB
    , lMB );
  MessageBox( NULL, szBuffer, _T("Example"), MB_OK );
  return 0;
}

 

Click to view the source code

See also CLoadLibray