BOOL MyLocalMacIP::GetSpaceInfo(CString &totalspace, CString &usedspace) { long long total = 0; long long used = 0; ::vector<CString> drivernames; int drivernum = 0; CString str; DWORD size = ::GetLogicalDriveStringsA(0, NULL); if (0 != size) { HANDLE heap = ::GetProcessHeap(); LPSTR lp = (LPSTR)HeapAlloc(heap, HEAP_ZERO_MEMORY, size*sizeof(TCHAR)); ::GetLogicalDriveStringsA(size*sizeof(TCHAR), lp); while(0 != *lp ) { /* we don‘t need C:*/ int str_num = strcmp((char*)lp, ("C:\\")); if (str_num == 0) { lp = strchr(lp, 0)+1; continue; } wchar_t* lp_buffer = conversion.CharToWchar(lp); UINT res = ::GetDriveTypeW(lp_buffer); if(DRIVE_FIXED == res) { CString str = lp; drivernames.push_back(str); drivernum++; } delete []lp_buffer; lp = strchr(lp, 0)+1; } } ULARGE_INTEGER FreeSpace, CallSpace, TotalSpace; for (int i = 0; i < drivernum; i++) { ::GetDiskFreeSpaceEx(drivernames[i], &FreeSpace, &CallSpace, &TotalSpace); total += CallSpace.QuadPart; used += FreeSpace.QuadPart; } string stotal = conversion.IntToString(total); string sused = conversion.IntToString(used); totalspace = CString(stotal.c_str()); usedspace = CString(sused.c_str()); return TRUE; }
- BOOL MyLocalMacIP::GetSpaceInfo(CString &totalspace, CString &usedspace)
- {
- long long total = 0;
- long long used = 0;
- ::vector<CString> drivernames;
- int drivernum = 0;
- CString str;
- DWORD size = ::GetLogicalDriveStringsA(0, NULL);
- if (0 != size)
- {
- HANDLE heap = ::GetProcessHeap();
- LPSTR lp = (LPSTR)HeapAlloc(heap, HEAP_ZERO_MEMORY, size*sizeof(TCHAR));
- ::GetLogicalDriveStringsA(size*sizeof(TCHAR), lp);
- while(0 != *lp )
- {
- /* we don‘t need C:*/
- int str_num = strcmp((char*)lp, ("C:\\"));
- if (str_num == 0)
- {
- lp = strchr(lp, 0)+1;
- continue;
- }
- wchar_t* lp_buffer = conversion.CharToWchar(lp);
- UINT res = ::GetDriveTypeW(lp_buffer);
- if(DRIVE_FIXED == res)
- {
- CString str = lp;
- drivernames.push_back(str);
- drivernum++;
- }
- delete []lp_buffer;
- lp = strchr(lp, 0)+1;
- }
- }
- ULARGE_INTEGER FreeSpace, CallSpace, TotalSpace;
- for (int i = 0; i < drivernum; i++)
- {
- ::GetDiskFreeSpaceEx(drivernames[i], &FreeSpace, &CallSpace, &TotalSpace);
- total += CallSpace.QuadPart;
- used += FreeSpace.QuadPart;
- }
- string stotal = conversion.IntToString(total);
- string sused = conversion.IntToString(used);
- totalspace = CString(stotal.c_str());
- usedspace = CString(sused.c_str());
- return TRUE;
- }