检查 CD-ROM 托盘状态

发布于 2024-09-28 07:24:07 字数 548 浏览 11 评论 0原文

我已经编写了一小段代码来使用 DeviceIoControl API 和正确的 IOCTL 打开/关闭 cd/dvd 驱动器托盘,但我似乎无法检查托盘状态。

根据msdn页面(http://msdn .microsoft.com/en-us/library/aa363404%28v=VS.85%29.aspx),如果驱动器加载了有效介质,并且 IOCTL_STORAGE_CHECK_VERIFY 应该成功,并且否则会失败并显示适当的错误代码。

因此,当 DeviceIoControl 失败时,我预计托盘打开时 21lasterror,托盘关闭时为 1112,但托盘中没有介质。设备。然而,在加载正确的媒体之前,它只会返回21

我错过了什么吗?还有其他方法可以找出托盘状态吗?

此致,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-10-05 07:24:07

那么,此 API 的文档指出它返回驱动器中是否有磁盘,但不返回托盘是否打开的信息。关于返回哪个错误代码的具体要求没有记录。在这两种情况下我也得到 21。

我查看了文档,但找不到任何记录的方法来执行您所要求的操作。对于大多数应用程序来说,托盘是否打开并不是那么有趣。

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.

旧时模样 2024-10-05 07:24:07

我找不到读取驱动器托盘状态的方法。相反,我正在检查执行弹出命令所需的时间,如 那里 的解释,如果需要超过 100 毫秒弹出返回 我假设我们确实弹出了媒体。如果弹出命令完成得太快,则假设托盘已打开并且需要关闭。
它似乎可以实现打开/关闭切换功能。
时间会证明一切:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文