@Lucamar:Thank you for explaining what those lines of code do.
Of course I needed to check for past 'Z'
I just want to mention a few things that have more to do with "programming style" than getting the information you need.
As you have already noticed having a construct such as
opens the possibility to an infinite loop - something "rarely" desirable. That's why in the example I provided I used
for I := 0 to ord('Z') - ord('A') do ...
ord('Z') - ord('A') is the zero based count of letters between A and Z. That loop is guaranteed to end and it doesn't process the superfluous bits in the bitmap (bits 26 through 31.)
if you want to exit the loop when the first CD drive is found simply add a test, such as
if DriveType = DRIVE_CDROM then break;
after getting the DriveType; (of course, you might want to either save the drive index somewhere or change the procedure to function and return its index to the caller.) if you know the zero based index, char(index + ord('A')) yields the drive letter.
About the
ZeroMemory(@DriveLetter, sizeof(DriveLetter));
Lucamar's explanation is right on the money. I just want to add that, in this particular case, it really isn't necessary because the call to
lstrcpy(DriveLetter, 'A:\');
not only puts the character sequence in there but, it also zero terminates it, therefore it overwrites the zeroes put in the variable by the call to ZeroMemory. I've just gotten into the habit of initializing all the buffers to zeroes. It prevents bugs (or makes them obvious) and it also makes debugging easier because you can tell at a glance what fields (e.g, in a record) have been set by your program and which ones have not. It also prevents having non-null terminated strings which are a common cause of buffer overruns. It's a good habit.
Another suggestion I'd like to make, use fullnames (or close to fullnames) for variables. having "Dr" for drive, saves typing but, doesn't help code readability. Good code is readable, which makes it easy to understand. Both, desirable features obtained with very little extra effort on the programmer's part.