WINBASEAPI BOOL WINAPI GetDiskFreeSpaceExA( __in_opt LPCSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailableToCaller, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes ); WINBASEAPI BOOL WINAPI GetDiskFreeSpaceExW( __in_opt LPCWSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailableToCaller, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes ); #ifdef UNICODE #define GetDiskFreeSpaceEx GetDiskFreeSpaceExW #else #define GetDiskFreeSpaceEx GetDiskFreeSpaceExA # endif // !UNICODE lpDirectoryName是驅(qū)動器的名稱。 lpFreeBytesAvailableToCaller是用戶可用的磁盤空間。 lpTotalNumberOfBytes是磁盤總共的空間。 lpTotalNumberOfFreeBytes是磁盤空閑的空間。以上都是字節(jié)為單位。 調(diào)用函數(shù)的例子如下(已驗(yàn)證): //獲取存儲設(shè)備信息 ULARGE_INTEGER nFreeBytesAvailable; ULARGE_INTEGER nTotalNumberOfBytes; ULARGE_INTEGER nTotalNumberOfFreeBytes; TCHAR FreeBuffer[64]; TCHAR TotalBuffer[64]; TCHAR TotalNumberOfFreeBytes[64]; INT cy; DWORD nFree = 0; if(GetDiskFreeSpaceEx(TEXT("\\Nandflash"), &nFreeBytesAvailable,&nTotalNumberOfBytes,&nTotalNumberOfFreeBytes)) { //nFreeBytesAvailable = nFreeBytesAvailable/1024; nFreeBytesAvailable.LowPart = nFreeBytesAvailable.LowPart/1024/1024; nTotalNumberOfBytes.LowPart = nTotalNumberOfBytes.LowPart/1024/1024; nTotalNumberOfFreeBytes.LowPart = nTotalNumberOfFreeBytes.LowPart/1024/1024; wsprintf(FreeBuffer,TEXT("可用容量 : %I64d.6 M"),nFreeBytesAvailable); wsprintf(TotalBuffer,TEXT("總?cè)萘?nbsp; : %I64d.6 M"),nTotalNumberOfBytes); wsprintf(TotalNumberOfFreeBytes,TEXT("剩余容量 : %I64d.6 M"),nTotalNumberOfFreeBytes);//("剩余容量:%I64d\r\n M") }
|