问题
I have written a small piece of code to open/close a cd/dvd drive tray using the DeviceIoControl API and the proper IOCTL but I don't seem to be able to check the tray status.
According to the msdn page (http://msdn.microsoft.com/en-us/library/aa363404%28v=VS.85%29.aspx), IOCTL_STORAGE_CHECK_VERIFY
is supposed to succeed if the drive is loaded with a valid media and fail otherwise with an appropriate error code.
So when DeviceIoControl fails, I expected 21
as lasterror
when the tray was opened and 1112
when the tray was closed but there was no media in the device. Yet it only returns 21
until a proper media is loaded.
Did I missed something ? Is there some other way to find out the tray status ?
Best Regards,
回答1:
Well, the documentation for this API states that it returns whether there is a disk in the drive and nothing about whether the tray is open or not. The specific requirements as to which error code is returns is not documented. I get 21 in both situations too.
I reviewed the documentation and could not find any documented way to do what you asked. To most applications, whether or not the tray is open is not that interesting.
回答2:
I could not find a way to read the status of the drive tray. Instead I'm checking the time it takes to execute the eject command as explain there, if it take more than 100ms for the eject to return I'm assuming we actually did eject the media. If the eject command completes too fast am then assuming the tray is opened and needs to be closed. It seems to do the trick to implement an open/close toggle function. Time will tell :)
来源:https://stackoverflow.com/questions/3969435/check-cd-rom-tray-status