Thursday, November 15, 2007

Find the logical drives within your system

Here is a way to find out the hard-disk drives within your system:

int iStrsLen;

char smzDrives [(3+1)*26+1];

char szDrive [3+1];

int i;

iStrsLen = GetLogicalDriveStrings (sizeof(smzDrives), smzDrives);

if( iStrsLen )

{

if (iStrsLen > sizeof(smzDrives))

{

// Buffer not big enough... eh?

}

else

{

// Parse the returned multi-string array.

i = 0;

while (smzDrives[i])

{

strcpy (szDrive, &(smzDrives[i]));

AfxMessageBox(szDrive);

while (smzDrives[i]) i++;

i++;

}

}

}

Instead of the function GetLogicalDriveStrings(), you can also use the function GetLogicalDrives() for this purpose.

No comments: