我完成拉!
#include <windows.h>
#include <stdio.h>
typedef BOOL (WINAPI *PGETDISKFREESPACEEX)(LPCSTR,
PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
BOOL MyGetDiskFreeSpaceEx(LPCSTR pszDrive)
{
PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
__int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
DWORD dwSectPerClust,
dwBytesPerSect,
dwFreeClusters,
dwTotalClusters;
BOOL fResult;
pGetDiskFreeSpaceEx = (PGETDISKFREESPACEEX) GetProcAddress(
GetModuleHandle("kernel32.dll"),
"GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
// Process GetDiskFreeSpaceEx results.
if(fResult)
{
printf("\n已用空间: %10.2fGB\n", (float)i64TotalBytes/(1024*1024*1024)-(float)i64FreeBytesToCaller/(1024*1024*1024));
printf("可用空间: %10.2fGB\n", (float)i64FreeBytes/(1024*1024*1024));
printf("总空间:
%10.2fGB\n", (float)i64TotalBytes/(1024*1024*1024));
}
return fResult;
}
else
{
fResult = GetDiskFreeSpaceA (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
// Process GetDiskFreeSpace results.
if(fResult)
{
printf("Total free bytes = I64d\n",
dwFreeClusters*dwSectPerClust*dwBytesPerSect);
}
return fResult;
}
}
int main(int argc, char *argv[])
{
MyGetDiskFreeSpaceEx ("c:");
}