procedure TForm1.Button1Click(Sender: TObject);
var
BufferLength: DWORD;
DriveStrings: LPTSTR;
CurrentDrive: LPTSTR;
ReturnValue: DWORD;
begin
BufferLength := GetLogicalDriveStrings(0,
nil);
if (BufferLength > 0)
then
begin
DriveStrings := LPTSTR(GetMemory(
(BufferLength + 1) * SizeOf(DriveStrings[0])));
if (DriveStrings <>
nil)
then
try
ReturnValue := GetLogicalDriveStrings(BufferLength, DriveStrings);
if (ReturnValue > 0)
and (ReturnValue <= BufferLength)
then
begin
CurrentDrive := DriveStrings;
while (CurrentDrive[0] <> #0)
do
begin
if (GetDriveType(CurrentDrive) = DRIVE_CDROM)
then
MessageBox(
Handle, CurrentDrive, '
CD-ROM', MB_OK);
CurrentDrive := LPTSTR(@CurrentDrive[StrLen(CurrentDrive) + 1]);
end;
end;
finally
FreeMemory(DriveStrings);
end;
end;
end;