关于>>得到磁盘的相关

得到磁盘信息:

void enumStore() { STOREINFO stinfo = {0}; HANDLE hPart = INVALID_HANDLE_VALUE; HANDLE hstore; TCHAR szInfo[100] = _T(""); stinfo.cbSize = sizeof(STOREINFO); hstore = FindFirstStore(&stinfo); if(hstore!=INVALID_HANDLE_VALUE) { do { RETAILMSG(1,(TEXT("Partion number:%ld /n"),stinfo.dwPartitionCount )); Size2String(stinfo.snNumSectors * stinfo.dwBytesPerSector,szInfo,100); RETAILMSG(1,(TEXT("enumPartion:%s szInfo=%s/n"),stinfo.szDeviceName,szInfo)); Size2String(stinfo.dwBytesPerSector, szInfo, 100); RETAILMSG(1,(TEXT("enumPartion:%s dwBytesPerSector=%s/n"),stinfo.szDeviceName,szInfo)); enumPartion(stinfo.szDeviceName,"//Hard Disk2//"); } while(FindNextStore(hstore, &stinfo)); } FindCloseStore(hstore); } LONGLONG enumPartion(LPCTSTR deviceName,CString szPartionName ) { PARTINFO partInfo = {0}; STOREINFO stinfo = {0}; HANDLE hPart= INVALID_HANDLE_VALUE; HANDLE hstore=INVALID_HANDLE_VALUE; TCHAR szInfo[100] = _T(""); stinfo.cbSize = sizeof(STOREINFO); partInfo.cbSize = sizeof(PARTINFO); hstore = OpenStore(deviceName); if(INVALID_HANDLE_VALUE!=hstore) { if(GetStoreInfo(hstore,&stinfo)==FALSE) return 0; hPart=FindFirstPartition(hstore, &partInfo); if(hPart==INVALID_HANDLE_VALUE) RETAILMSG(1,(TEXT("no find Partion info"))); if(hPart!=INVALID_HANDLE_VALUE) { do { RETAILMSG(1,(TEXT("enumPartion:%s /n"),partInfo.szVolumeName)); if(szPartionName.Right(1).Compare(_T("//"))==0) szPartionName=szPartionName.Left(szPartionName.GetLength()-1); if(szPartionName.Compare(partInfo.szVolumeName)==0) { CloseHandle(hstore); FindClosePartition(hPart); return partInfo.snNumSectors*stinfo.dwBytesPerSector; } } while(FindNextPartition(hPart, &partInfo)); } } CloseHandle(hstore); FindClosePartition(hPart); return 0L; } //

 

---------------------------------------------------------------------------------------

得到磁盘空间:

LONGLONG GetDiskSpace(LPCWSTR disk) { ULARGE_INTEGER lpuse; ULARGE_INTEGER lptotal; ULARGE_INTEGER lpfree; LONGLONG llsize; TCHAR szInfo[100] = _T(""); GetDiskFreeSpaceEx(disk,&lpuse,&lptotal,&lpfree); //RETAILMSG(1,(TEXT("disk:%s used:%ld free:%ld total:%ld/n"),disk,lpuse.QuadPart/1024/1024,lpfree.QuadPart/1024/1024,lptotal.QuadPart/1024/1024)); Size2String(lpuse.QuadPart, szInfo, 100); //RETAILMSG(1,(TEXT("lpuse.QuadPart=%s/n"),szInfo)); llDiskFreeSize=lpuse.QuadPart; szDiskFreeSize.Format(_T("%s"),szInfo); // llDiskTotalSize=lptotal.QuadPart; Size2String(lptotal.QuadPart, szInfo, 100); szDiskTotalSize.Format(_T("%s"),szInfo); //RETAILMSG(1,(TEXT("szDiskTotalSize=%s szDiskFreeSize=%s /n"),szDiskTotalSize,szDiskFreeSize )); return (LONGLONG)lptotal.QuadPart; } // -------------------------------------------------------------------- BOOL Size2String(LONGLONG llBytes, LPTSTR pszSize, DWORD cLen) // -------------------------------------------------------------------- { double bytes = (double)llBytes; DWORD cIter = 0; LPCTSTR pszUnits[] = { _T("B"), _T("K"), _T("M"), _T("G"), _T("T") }; DWORD cUnits = sizeof(pszUnits) / sizeof(pszUnits[0]); // move from bytes to kb, to mb, to gb and so on diving by 1024 while(bytes >= 1024 && cIter < (cUnits-1)) { bytes /= 1024; cIter++; } _sntprintf(pszSize, cLen, _T("%.0f%s"), bytes, pszUnits[cIter]); return TRUE; }

你可能感兴趣的:(关于>>得到磁盘的相关)