This shows you the differences between two versions of the page.
— |
available_drives [2011/12/12 06:55] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== List all available drives ====== | ||
+ | |||
+ | <file>This code snippet is originally from the former WinAPI site www.winapi.net</file> | ||
+ | |||
+ | 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: | ||
+ | |||
+ | <code c>#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); | ||
+ | } | ||
+ | </code> | ||