I'm writing an application that's going to work with audio CDs and mixed CDs. I would like to have a method of determining whether there is an audio or mixed-type (with at least one audio track) disc currently in the drive that the application uses.
So far, I was able to identify that the drive is a CD-ROM by GetDriveType
. However, it turns out that identifying the media that is actually inside the drive is not that easy. This is what I've got so far :
int drive_has_audio_disc(const char *root_path)
{
char volume_name[MAX_PATH+1];
BOOL winapi_rv;
DWORD fs_flags;
int rv;
winapi_rv = GetVolumeInformation(root_path, volume_name, sizeof(volume_name),
NULL, NULL, &fs_flags, NULL, 0);
if(winapi_rv != 0)
{
rv = (strcmp(volume_name, "Audio CD") == 0 &&
(fs_flags & FILE_READ_ONLY_VOLUME));
}
else
{
rv = (GetLastError() == ERROR_INVALID_PARAMETER) ? 0 : -1;
}
return rv;
}
However, it relies on the fact that Windows assigns the name "Audio CD" to all discs that are recognized as audio. This doesn't feel right, and is going to fail miserably on mixed-mode CDs, since their name in Windows is determined by the volume name of the data track. Also, the else
block is here because I've noticed that GetVolumeInformation
returns an error with GetLastError
equal to ERROR_INVALID_PARAMETER
when there is no disc in the drive at all.
Ideally, I'm looking for something like the CDROM_DISC_STATUS
ioctl present on Linux. It returns CDS_NO_INFO
, CDS_AUDIO
, CDS_MIXED
, or some other values, depending on the contents of the disc.
Is there any other way of handling this? And what about mixed-mode discs?