Sunday, July 17, 2022

CPP: Windows: Get logical drives

CPP: Windows: Get logical drives

Retrieves a bitmask representing the currently available disk drives.
#include <iostream>
#include <Windows.h>
int main()
{
DWORD drives = GetLogicalDrives();
char start = 'A';
for (int i = 1; i <= 32; i++) {
auto x = i - 1;
auto driveBit = unsigned(1 << x);
if (drives & driveBit) {
std::cout << (char)(start + i - 1) << ":" << std::endl;
}
}
return 0;
}

Notes:
- Tested using Visual Studio 2022 C++ Windows Console template
Reference(s):
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrives

No comments:

Fedora install screen chronicle

Fedora install screen chronicle Below are links to Fedora installation screens. It is interesting to see how it has evolved over time. Fe...