VB icon

Logical Drive Enumerator

Email
Submitted on: 1/1/2015 5:51:00 PM
By: Adam Presley (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: C, Microsoft Visual C++, Borland C++
Views: 887
 
     This code enumerates a list of the logical drive letters recognized by Windows, and displays this list in a message box.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Logical Drive Enumerator
//**************************************
#include <windows.h>
#include <string.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Logical Drive Enumerator
// Description:This code enumerates a list of the logical drive letters recognized by Windows, and displays this list in a message box.
// By: Adam Presley (from psc cd)
//
// Assumes:This code works only in Win32 enviornment.
//**************************************

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
DWORD Drives;
char output[255];
DWORD bit_modify[] = {
 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200,
 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, 0x10000,
 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000,
 0x800000, 0x1000000, 0x2000000
};
char *drive_list[] = {
 "A: ", "B: ", "C: ", "D: ", "E: ", "F: ", "G: ", "H: ", "I: ",
 "J: ", "K: ", "L: ", "M: ", "N: ", "O: ", "P: ", "Q: ",
 "R: ", "S: ", "T: ", "U: ", "V: ", "W: ", "Y: ", "Z: "
};
// ---- Clear the output buffer ----
strcpy(output, "");
// ---- Now, get the drives ----
Drives = GetLogicalDrives();
if(Drives == 0) {
 MessageBox(NULL, "There was an error getting the list of logical drives.",
 "Error!", MB_OK|MB_ICONERROR);
 return -1;
}
// ---- Create the list in the variable 'output' ----
for(int loop = 0; loop < 25; loop++)
 if(Drives & bit_modify[loop]) strcat(output, drive_list[loop]);
MessageBox(NULL, output, "Drives List...", MB_OK|MB_ICONINFORMATION);
return 0;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.