Trouble with GetLogicalDrives() function
-
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
-
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
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 //...
-
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
You should also take a look at the documentation for GetLogicalDriveStrings() and GetDriveType().
-
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
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