...check if an audio-cd is in the cd drive?

Author: Ken White

Category: Multimedia

function IsAudioCD(Drive: Char): Boolean;
var
  
DrivePath: string;
  MaximumComponentLength: DWORD;
  FileSystemFlags: DWORD;
  VolumeName: string;
  OldErrorMode: UINT;
  DriveType: UINT;
begin
  
Result := False;
  DrivePath := Drive + ':\';
  OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    
DriveType := GetDriveType(PChar(DrivePath));
  finally
    
SetErrorMode(OldErrorMode);
  end;
  if DriveType <> 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;


procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
IsAudioCD('D') then
    
ShowMessage('Audio-CD found in drive D.')
  else
    
ShowMessage('No Audio-CD found in drive D.');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base