BCB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BCB] DWORD separation!!



Hi, I've just subscribed to this list.


>     I am very new to the field of BCB. I need to know the number of logical
> drives that are present. But to do so I have to call the GetLogicalDrives()
> Api. But this returns a DWORD whoose bits tells the answer to the puzzle.
> Now the problem is that I can get a way to split it up to find out what
> drives are present.

Something like this should work:

char Drive;
int Mask;
DWORD Status = GetLogicalDrives();
for(Drive = 'A', Mask = 1; Drive <= 'Z'; Drive++, Mask <<= 1)
{
   if(Status & Mask)
   {
        The logical drive noted by Drive is available
   }
}

I've never tried this one.

You can also use GetDriveType:
char* Path = "A:\";
char Drive;
for(Drive = 'A'; Drive <= 'Z'; Drive++)
{
   *Path = Drive;
   swtich(GetDriveType(Path))
   {
        case 0:
        case 1:
            // drive does not exist
            break;
        default:
            // drive exists
   }
}

I've used this approach several times.

GetDriveType returns the type of the drive (CD, fixed, removable,
etc.) also.

Tom



W Komornicki's Home Page | Main Index | Thread Index