GetLogicalDrives,GetLogicalDriveStrings,GetDriveType
#include "stdafx.h" #include#include #include #include #ifdef _UNICODE #define tcout wcout #else #define tcout cout #endif int _tmain(int argc, _TCHAR* argv[]) { TCHAR tables[][4] = { _T("A://"), _T("B://"), _T("C://"), _T("D://"), _T("E://"), _T("F://"), _T("G://"), _T("H://") }; std::bitset<32> bitMap(::GetLogicalDrives()); for (size_t i = 0; i < bitMap.size() && i < sizeof(tables) / 4; i++) { if (bitMap[i]) { std::tcout << tables[i] << std::endl; } } std::cout << _T("--------------------------------------------") << std::endl; TCHAR pszBuffer[MAX_PATH]; DWORD nCnt = ::GetLogicalDriveStrings(MAX_PATH, pszBuffer); TCHAR* p; if (nCnt > 0) { p = pszBuffer; while (*p != _T('/0')) { std::tcout << p << std::endl; p = p + _tcslen(p) + 1; } } /*TCHAR szBuffer[MAX_PATH]; HANDLE handle = ::FindFirstVolume(szBuffer, MAX_PATH); if (handle != NULL) { do{ std::tcout << szBuffer << std::endl; }while (::FindNextVolume(handle, szBuffer, MAX_PATH)); ::FindVolumeClose(handle); }*/ for (size_t i = 0; i < sizeof(tables) / 4; i++) { UINT nRet = ::GetDriveType(tables[i]); //#define DRIVE_UNKNOWN 0 //#define DRIVE_NO_ROOT_DIR 1 //#define DRIVE_REMOVABLE 2 //#define DRIVE_FIXED 3 //#define DRIVE_REMOTE 4 //#define DRIVE_CDROM 5 //#define DRIVE_RAMDISK 6 switch (nRet) { case DRIVE_UNKNOWN: std::tcout << tables[i] << _T("DRIVE_UNKNOWN") << std::endl; break; case DRIVE_NO_ROOT_DIR: std::tcout << tables[i] << _T("DRIVE_NO_ROOT_DIR") << std::endl; break; case DRIVE_REMOVABLE: std::tcout << tables[i] << _T("DRIVE_REMOVABLE") << std::endl; break; case DRIVE_FIXED: std::tcout << tables[i] << _T("DRIVE_FIXED") << std::endl; break; case DRIVE_REMOTE: std::tcout << tables[i] << _T("DRIVE_REMOTE") << std::endl; break; case DRIVE_CDROM: std::tcout << tables[i] << _T("DRIVE_CDROM") << std::endl; break; case DRIVE_RAMDISK: std::tcout << tables[i] << _T("DRIVE_RAMDISK") << std::endl; break; } } return 0; }