Link to home
Start Free TrialLog in
Avatar of tanmh
tanmh

asked on

Hard disk space

hi,
please advise if there's any Win32 API which allows the programmer to check the hard disk space utilised/free in the codes.

thanks,
andrea
Avatar of cyrilbdt
cyrilbdt

GetDiskFreeSpaceEx
Avatar of tanmh

ASKER

hi,
can u pls provide an example of how to call this func to get
the free disk space?

thanks.
Avatar of tanmh

ASKER

although the API is correct but after asking for an
example for so long, there was no answer.

other experts, would appreciate it if you can help. Basically, I don't know how to pass the parameters for the API, what's PULARGE_INTEGER?

BOOL GetDiskFreeSpaceEx(
  LPCTSTR lpDirectoryName,                
  PULARGE_INTEGER lpFreeBytesAvailableToCaller,                                                
  PULARGE_INTEGER lpTotalNumberOfBytes,    
  PULARGE_INTEGER lpTotalNumberOfFreeBytes );
That is example of GetDiskFreeSpace:

  DWORD  lpSectorsPerCluster;      // address of sectors per cluster
  DWORD  lpBytesPerSector;      // address of bytes per sector
  DWORD  lpNumberOfFreeClusters;      // address of number of free clusters
  DWORD  lpTotalNumberOfClusters;       // address of total number of clusters
  GetDiskFreeSpace("C:\\",

    &lpSectorsPerCluster,      // address of sectors per cluster
    &lpBytesPerSector,      // address of bytes per sector
    &lpNumberOfFreeClusters,      // address of number of free clusters
    &lpTotalNumberOfClusters       // address of total number of clusters
   );
  DWORD lFree = lpNumberOfFreeClusters * lpSectorsPerCluster *
   lpBytesPerSector;
Regrds, Alex
Avatar of tanmh

ASKER

hi Alex,
thanks for your example.
Do u have the sample for GetDiskFreeSpaceEx instead?
or do I have to use GetDiskFreeSpace and then calculate the free disk space myself?

thanks,
Andrea
Avatar of tanmh

ASKER

hi Alex,

I've tried out your sample code and I got the following error:

C:\ESPdev\bin\trydatetime\main.cpp(133) : error C2664: 'GetDiskFreeSpaceW' : cannot convert parameter 1 from 'char [4]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Please advise.

Thanks, Andrea
Avatar of tanmh

ASKER

again after so long, no response.

would appreciate if any expert can followup and provide me with a solution.

thanks,
andrea
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tanmh

ASKER

hi Alex,
Thanks for your help.
I've tried out on my VC++ v6.0 compiler.
For the 1st variant
-------------------
error C2664: 'GetDiskFreeSpaceW' : cannot convert parameter 1 from 'char [4]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

For the 2nd variant
-------------------
the compiler complained that _dos_getdiskfree(3,&d) is undeclared identifier even though i included <dos.h>

Just to check with you, for variant 1, did u set your compiler options?

Regards,
Andrea
Avatar of tanmh

ASKER

I've solved my problem already.
thanks.