#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#define BUFSIZE 1024
int main(){
DWORD lpSectorsPerCluster;
DWORD lpBytesPerSector;
DWORD lpNumberOfFreeClusters;
DWORD lpTotalNumberOfCluster;
GetDiskFreeSpace(TEXT("D:"),
&lpSectorsPerCluster,
&lpBytesPerSector,
&lpNumberOfFreeClusters,
&lpTotalNumberOfCluster);
printf("GetDiskFreeSpace获取的磁盘容量信息\n");
printf("每簇的扇区数量%d\n",lpSectorsPerCluster);
printf("每扇区的字节数%d\n",lpBytesPerSector);
printf("空闲的簇数量%d\n",lpNumberOfFreeClusters);
printf("总簇数%d\n",lpTotalNumberOfCluster);
printf("磁盘容量%I64d\n",(DWORD64)lpTotalNumberOfCluster*(DWORD64)lpSectorsPerCluster*(DWORD64)lpBytesPerSector);
printf("空闲容量%I64d\n\n\n\n",(DWORD64)lpNumberOfFreeClusters*(DWORD64)lpSectorsPerCluster*(DWORD64)lpBytesPerSector);
DWORD lpFreeBytesAvailableToCaller;
DWORD lpTotalNumberOfBytes;
DWORD lpTotalNumberOfFreeBytes;
GetDiskFreeSpaceEx(TEXT("D:"), //获取不准确
(PULARGE_INTEGER)&lpFreeBytesAvailableToCaller,
(PULARGE_INTEGER)&lpTotalNumberOfBytes,
(PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
);
printf("GetDiskFreeSpaceEx获取的磁盘容量信息\n");
printf("总容量字节数%I64d\n",lpTotalNumberOfBytes);
printf("可用空闲字节数%I64d\n",lpFreeBytesAvailableToCaller);
printf("总空闲字节数%I64d\n",lpTotalNumberOfFreeBytes);
system("pause");
return 0;
}
|