This code snippet is originally from the former WinAPI site www.winapi.net
Sometimes you need to know about all logical drives. The WinAPI gives us for that the function GetLogicalDrives()
. It returns a bit mask which has to be analysed. Here is an example how:
#include <windows.h> #include <tchar.h> #include <shlwapi.h> #include <stdio.h> #ifndef BITSPERBYTE #define BITSPERBYTE 8 #endif #define IS_BIT(val, bit) ((val) & (1 << (bit))) int _tmain(void) { DWORD dwLogicalDrives, x; TCHAR szRoot[32]; dwLogicalDrives = GetLogicalDrives(); for(x = 0; x < (sizeof(dwLogicalDrives) * BITSPERBYTE); x++) { if(IS_BIT(dwLogicalDrives, x)) { PathBuildRoot(szRoot, x); _tprintf(TEXT("%s - DriveType: 0x%08X\n"), szRoot, GetDriveType(szRoot)); } } return(0); }