PDA

View Full Version : How to detect if there is a DVD in CDROM


aithai
18th June 2007, 17:33
Hi,
I cannot get a decent code to detect if there is a DVD in the CDROM. I use WM_DEVICECHANGE - which in fact will correctly detect only when the DVD is inserted or ejected. The two events firing this change, as you know are:
DBT_DEVICEARRIVAL;
DBT_DEVICEREMOVECOMPLETE

I hope to get comments on how to correctly detect if there is or NOT a DVD in the CDROM.

Delphi codings appreciated, but not necessary.

Thank you.

foxyshadis
19th June 2007, 00:03
Moving to development, where more experienced folks will see it.

I don't think there's any fullproof way to tell, given that more than a few times I've ejected a disc and inserted a new one, only for explorer to still show the old disc's file structure (until one attempts to open something). I suspect determining the exact contents of the drive might involve ASPI commands, but I have no experience there.

LoRd_MuldeR
19th June 2007, 00:33
Maybe you can use GetDriveType (http://msdn2.microsoft.com/en-us/library/aa364939.aspx) to check that the drive is a CDROM drive and GetVolumeInformation (http://msdn2.microsoft.com/en-us/library/aa364993.aspx) to check the drive's state...


Also note the remarks of GetVolumeInformation:

When a user attempts to get information about a floppy drive that does not have a floppy disk, or a CD-ROM drive that does not have a compact disc, the system displays a message box for the user to insert a floppy disk or a compact disc, respectively. To prevent the system from displaying this message box, call the SetErrorMode function with SEM_FAILCRITICALERRORS.