1. Home
  2. Computing & Technology
  3. Delphi Programming

Does my CD-ROM drive contain an audio CD?

By , About.com Guide

We can use the Windows API function GetDriveType() to test if the drive is a CD-ROM drive then use the Windows API function GetVolumeInformation() to test if the VolumeName is 'Audio CD'.

~~~~~~~~~~~~~~~~~~~~~~~~~
function IsAudioCD(Drive : char) : bool;
var
   DrivePath : string;
   MaximumComponentLength : DWORD;
   FileSystemFlags : DWORD;
   VolumeName : string;
begin
   Result := false;
   DrivePath := Drive + ':\';
   if GetDriveType(PChar(DrivePath))
   <> DRIVE_CDROM then exit;
   SetLength(VolumeName, 64) ;
   GetVolumeInformation(PChar(DrivePath),
                        PChar(VolumeName),
                        Length(VolumeName),
                        nil,
                        MaximumComponentLength,
                        FileSystemFlags,
                        nil,
                        0) ;
   if lStrCmp(PChar(VolumeName),'Audio CD') = 0
   then result := true;
end;


{Usage:}
procedure TForm1.Button1Click(Sender: TObject) ;
begin
  if not IsAudioCD('D') then
   ShowMessage('Not an Audio CD in drive D') ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Show / Hide Desktop Icons
« Hide a process in the 'Close Program' Window

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2000 Delphi Tips
  7. Does my CD-ROM drive contain an audio CD?

©2009 About.com, a part of The New York Times Company.

All rights reserved.