I am trying to get my Win32 Visual C++ App to check if my CD Rom Tray has a CD Rom in it using MCI functions, and if it does, proceed. If not, provide the user with an error. How can I check if a CD is inserted in the CD Rom Tray?
Asked
Active
Viewed 154 times
0
-
I don't know if there is a nicer Win32 way of doing this. The way I've always done it is to use DeviceIoControl() SCSI pass-through to send MMC Media commands directly to the drive. That not only tells IF a disc is in the drive, but WHAT KIND of disc (CD-R, DVD±R/W, BD-R/E, etc). But this is quite low level and not trivial, it took me a long while to get the commands right. You can find copies of the MMC command documentation online. – Remy Lebeau Jan 15 '21 at 02:44
-
1Just go ahead and do what you intended to do anyway, and observe the outcome. No need to introduce a TOCTTOU race. – IInspectable Jan 15 '21 at 02:49
-
Actually, if all you are interested in is the existence of the CD disc, [IOCTL_STORAGE_CHECK_VERIFY](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddstor/ni-ntddstor-ioctl_storage_check_verify) or [IOCTL_CDROM_GET_DRIVE_GEOMETRY](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddcdrm/ni-ntddcdrm-ioctl_cdrom_get_drive_geometry) might work for you. – Remy Lebeau Jan 15 '21 at 02:54
-
@remylebeau Would you be able to provide an example of this? – Alyssa Jan 15 '21 at 02:54
-
@Alyssa unfortunately, I don't have access to that code anymore. I wrote it years ago, and it was lost in a later system crash. – Remy Lebeau Jan 15 '21 at 02:55