In this Tutorial we are going to go over how to gather & then display all of the drives on your Windows System.
1st, we need to include the Windows.h header, as it is required by the two functions we are going to use from the Widows API.
These functions are GetLogicalDriveStrings & GetDriveType.
CODE
#include <stdio.h>
#include <windows.h> // required for GetLogicalDriveStrings & GetDriveType
#define MAX 256
These functions are fairly simple to use. In order to get started, we are going to need to declare a buffer. The function GetLogicalDriveStrings simply fills a buffer with Null terminated strings. This is both convenient, & inconvenient. It's convenient, because the strings that it prepares can be fed directly into GetDriveType with no modification. It's inconvenient, because of the Null termination we need to parse it with a pointer.
So getting started, lets create a buffer, & a pointer.
CODE
int main(void) {
int dr_type=99;
char dr_avail[MAX];
char *temp=dr_avail;
Now we'll fill our buffer, as well as indicate the max size of the buffer. Since we defined MAX to be 256 earlier, we'll just use that

CODE
GetLogicalDriveStrings(MAX,dr_avail);
Now dr_avail, defined as char, will contain a Null terminated string of all of our drive letters. Now we'll parse that into the pointer at each Null, & then deal with them individually. Once they are seperated into the Temp pointer, we will pass that pointer to GetDriveType. Since the string already holds the format that GetDriveType requires, we don't need to alter anything. GetDriveType requires the drive letter, the colon, & it must have the backspace. Again, this is exactly how GetLogicalDriveStrings prepares it

CODE
while(*temp!=NULL) { // Split the buffer by null
dr_type=GetDriveType(temp);
Now dr_type holds the int return value from GetDriveType. Lets go over the different return values!
CODE
switch(dr_type) {
case 0: // Unknown
printf("%s : Unknown Drive type\n",temp);
break;
case 1: // Invalid
printf("%s : Drive is invalid\n",temp);
break;
case 2: // Removable Drive
printf("%s : Removable Drive\n",temp);
break;
case 3: // Fixed
printf("%s : Hard Disk (Fixed)\n",temp);
break;
case 4: // Remote
printf("%s : Remote (Network) Drive\n",temp);
break;
case 5: // CDROM
printf("%s : CD-Rom/DVD-Rom\n",temp);
break;
case 6: // RamDrive
printf("%s : Ram Drive\n",temp);
break;
}
Yup, just the seven different values. Now we just need to increment our pointer & run the loop again.
CODE
temp += lstrlen(temp) +1; // incriment the buffer
}
return 0;
}
& that's it! I hope you find this useful. Here is the entire code in one chunk.
cpp
#include <stdio.h>
#include <windows.h>
#define MAX 256
int main(void) {
int dr_type=99;
char dr_avail[MAX];
char *temp=dr_avail;
/* 1st we fill the buffer */
GetLogicalDriveStrings(MAX,dr_avail);
while(*temp!=NULL) { // Split the buffer by null
dr_type=GetDriveType(temp);
switch(dr_type) {
case 0: // Unknown
printf("%s : Unknown Drive type\n",temp);
break;
case 1: // Invalid
printf("%s : Drive is invalid\n",temp);
break;
case 2: // Removable Drive
printf("%s : Removable Drive\n",temp);
break;
case 3: // Fixed
printf("%s : Hard Disk (Fixed)\n",temp);
break;
case 4: // Remote
printf("%s : Remote (Network) Drive\n",temp);
break;
case 5: // CDROM
printf("%s : CD-Rom/DVD-Rom\n",temp);
break;
case 6: // RamDrive
printf("%s : Ram Drive\n",temp);
break;
}
temp += lstrlen(temp) +1; // incriment the buffer
}
return 0;
}