Enumerating Drive Letters

This is a discussion on Enumerating Drive Letters within the Windows Programming forums, part of the Platform Specific Boards category; I have a method of getting drive letters but I don't like it. You see, we currently do a listbox, ...

  1. #1
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Enumerating Drive Letters

    I have a method of getting drive letters but I don't like it. You see, we currently do a listbox, hidden. We call SendMessage(hTempList, LB_DIR, DDL_DRIVES | DDL_EXCLUSIVE, (LONG)(LPSTR)"*"); and then get the strings out of the list box. I HATE that solution and I was hoping someone could give me something better.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I think GetLogicalDriveStrings() will do it. So never mind.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Glad to be of service.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    I know you have cracked it, but here's a way to simply get the drive letter as a char;

    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    #include <windows.h>
    #include <cstring>
    
    
    int main(int argc, char* argv[])
    {  
    	const char* szLookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    	DWORD dwBits = GetLogicalDrives();
    	const DWORD dwMask = 1;
    
    
    	for(int i = 0;i < strlen(szLookup);i++){
    		if(dwMask & dwBits)
    			cout << "Found Drive " << szLookup[i] << endl;
    		dwBits >>= dwMask;
    	}	
    	
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SATA HDD failure
    By PING in forum Tech Board
    Replies: 4
    Last Post: 12-23-2008, 12:25 AM
  2. Replies: 2
    Last Post: 07-06-2005, 08:11 PM
  3. drive letters
    By metsman20 in forum Tech Board
    Replies: 4
    Last Post: 12-11-2003, 12:54 PM
  4. Spin A Drive and such
    By Seph_31 in forum C Programming
    Replies: 15
    Last Post: 11-20-2003, 06:04 PM
  5. Detecting CD drive letters in the Win32 API...
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 10-07-2002, 03:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21