Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Trouble with GetLogicalDrives() function

Trouble with GetLogicalDrives() function

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dev578
    wrote on last edited by
    #1

    As said before, what I am tying to do is get the letters of all the CD/DVD drives on the users computer using MFC. This is what I have so far: DWORD Drives = GetLogicalDrives(); CString FormatString; FormatString.Format("%i",Drives); DriveControl.SetWindowText(FormatString); FormatString returns 61... I have no idea why it is returning 61. I am assuming that I am doing it wrong? If anyone could show me how to do this right, that would be great. -Dev578

    C P 3 Replies Last reply
    0
    • D Dev578

      As said before, what I am tying to do is get the letters of all the CD/DVD drives on the users computer using MFC. This is what I have so far: DWORD Drives = GetLogicalDrives(); CString FormatString; FormatString.Format("%i",Drives); DriveControl.SetWindowText(FormatString); FormatString returns 61... I have no idea why it is returning 61. I am assuming that I am doing it wrong? If anyone could show me how to do this right, that would be great. -Dev578

      C Offline
      C Offline
      Curi0us_George
      wrote on last edited by
      #2

      GetLogicalDrives returns a bit mask. The individual bits represent the available drive letters. GetLogicalDrives() returned 61 on your computer. A more useful way to look at this would be in binary. i.e. 111101 (or 00000000000000000000000000111101) Starting with the least most significant bit (the right one), we see that you: have an A drive have no B drive have a C drive have a D drive have a E drive have a F drive have no drives G - Z. In your code, you can use a bitwise AND operation to parse out the individual drives' availability. i.e: DWORD drives = GetLogicalDrives(); if (drives & 0x01) // have A if (drives & 0x02) // have B if (drives & 0x04) // have C //...

      1 Reply Last reply
      0
      • D Dev578

        As said before, what I am tying to do is get the letters of all the CD/DVD drives on the users computer using MFC. This is what I have so far: DWORD Drives = GetLogicalDrives(); CString FormatString; FormatString.Format("%i",Drives); DriveControl.SetWindowText(FormatString); FormatString returns 61... I have no idea why it is returning 61. I am assuming that I am doing it wrong? If anyone could show me how to do this right, that would be great. -Dev578

        C Offline
        C Offline
        Curi0us_George
        wrote on last edited by
        #3

        You should also take a look at the documentation for GetLogicalDriveStrings() and GetDriveType().

        1 Reply Last reply
        0
        • D Dev578

          As said before, what I am tying to do is get the letters of all the CD/DVD drives on the users computer using MFC. This is what I have so far: DWORD Drives = GetLogicalDrives(); CString FormatString; FormatString.Format("%i",Drives); DriveControl.SetWindowText(FormatString); FormatString returns 61... I have no idea why it is returning 61. I am assuming that I am doing it wrong? If anyone could show me how to do this right, that would be great. -Dev578

          P Offline
          P Offline
          P Rex
          wrote on last edited by
          #4

          Try this: DWORD dwLogicalDrives = ::GetLogicalDrives(); char szDriveRoot[] = ""; if(dwLogicalDrives) { for(int iCnt = 0; iCnt < 32; ++iCnt) { memset(szDriveRoot, 0, sizeof(szDriveRoot)); if(dwLogicalDrives & (1 << iCnt)) { // Set drive root sprintf(szDriveRoot, "%c:\\", iCnt + 'A'); UINT uiDriveType = ::GetDriveType(szDriveRoot); switch(uiDriveType) { // Unknown case DRIVE_UNKNOWN: TRACE1(_T("%s is unknown\n"), szDriveRoot); break; // Root path invalid case DRIVE_NO_ROOT_DIR: TRACE1(_T("Partition %s is no root drive\n"), szDriveRoot); break; // Removable drive case DRIVE_REMOVABLE: TRACE1(_T("Partition %s is a removable device\n"), szDriveRoot); break; // Fixed drive case DRIVE_FIXED: TRACE1(_T("Partition %s is a Harddisk\n"), szDriveRoot); break; // Network drive case DRIVE_REMOTE: TRACE1(_T("Partition %s is a network drive\n"), szDriveRoot); break; // CD-ROM case DRIVE_CDROM: TRACE1(_T("Partition %s is CD-ROM\n"), szDriveRoot); break; // RAM-Disk case DRIVE_RAMDISK: TRACE1(_T("Partition %s is no RAM-Disk\n"), szDriveRoot); break; } } } Pascal

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups