其实主要用到的就是以下四个函数:
GetLogicalDriveStrings();
GetDriverType();
GetDiskFreeSpace();
GetDiskFreeSpaceEx();
//如果你想获得硬盘大小,可以参见下面的代码:
DWORD dwTotalDiskSpace,dwFreeDiskSpace,dwUsedDiskSpace;
ULARGE_INTEGER uiFreeBytesAvailableToCaller;
ULARGE_INTEGER uiTotalNumberOfBytes;
ULARGE_INTEGER uiTotalNumberOfFreeBytes;
if(GetDiskFreeSpaceEx(szPath, &uiFreeBytesAvailableToCaller,
&uiTotalNumberOfBytes, &uiTotalNumberOfFreeBytes))
{
dwTotalDiskSpace = (DWORD)(uiTotalNumberOfBytes.QuadPart / 1024 / 1024);
dwFreeDiskSpace = (DWORD)(uiFreeBytesAvailableToCaller.QuadPart >> 20);
dwUsedDiskSpace = dwTotalDiskSpace - dwFreeDiskSpace;
TRACE("硬盘%s::总空间%dMB, 已用%dMB, 可用%dMB\n", szPath,
dwTotalDiskSpace, dw