如何以编程方式防止DVD弹出 [英] How to prevent DVD eject programmatically

查看:75
本文介绍了如何以编程方式防止DVD弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将文件复制到DVD。我希望在复制过程中防止DVD弹出。



我尝试过:



使用的DeviceIoControl(hVolume,IOCTL_STORAGE_EJECTION_CONTROL,& PMRBuffer,sizeof(PREVENT_MEDIA_REMOVAL),NULL,0,& dwBytesReturned,NULL);



锁定工作很好,直到复制第一个文件。复制第一个文件后,我可以弹出DVD。我希望锁可以工作,直到所有文件都被复制



这是DeviceIoControl()API中的错误吗?任何解决方法?

My application copies files to DVD. I want to prevent DVD eject during this copy.

What I have tried:

Used DeviceIoControl( hVolume,IOCTL_STORAGE_EJECTION_CONTROL,&PMRBuffer, sizeof(PREVENT_MEDIA_REMOVAL),NULL, 0,&dwBytesReturned, NULL);

The lock works fine until the first file is copied. After copying of first file i am able to eject the DVD. I want the lock to work until all files are copied

Is this a bug in DeviceIoControl() API? Any workarounds?

推荐答案

认为你缺少一个参数来传递完整的文件堆栈,这样编写控件就不会有文件写入堆栈所以它不会第一次完成后立即弹出CD



然而这可能有助于理解函数的参数



think you are missing one parameter to pass full stack of files so that writing control would no there are files to be written in the stack so it wont eject the CD as soon as first completes

however this may help to understand the function's parameters well

Call CreateFile with GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, and OPEN_EXISTING. The lpFileName parameter should be \.\X: (where X is the real drive letter). All other parameters can be zero.

Lock the volume by issuing the FSCTL_LOCK_VOLUME IOCTL via DeviceIoControl. If any other application or the system is using the volume, this IOCTL fails. Once this function returns successfully, the application is guaranteed that the volume is not used by anything else in the system.

Dismount the volume by issuing the FSCTL_DISMOUNT_VOLUME IOCTL. This causes the file system to remove all knowledge of the volume and to discard any internal information that it keeps regarding the volume.

Make sure the media can be removed by issuing the IOCTL_STORAGE_MEDIA_REMOVAL IOCTL. Set the PreventMediaRemoval member of the PREVENT_MEDIA_REMOVAL structure to FALSE before calling this IOCTL. This stops the device from preventing the removal of the media.

Eject the media with the IOCTL_STORAGE_EJECT_MEDIA IOCTL. If the device doesn't allow automatic ejection, then IOCTL_STORAGE_EJECT_MEDIA can be skipped and the user can be 
instructed to remove the media.

Close the volume handle obtained in the first step or issue the FSCTL_UNLOCK_VOLUME IOCTL. This allows the drive to be used by other processes.





希望你的代码语法是这样的 -





hope your code syntax is like this -

bResult = DeviceIoControl(hDevice,                       // device to be queried
                            IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
                            NULL, 0,                       // no input buffer
                            pdg, sizeof(*pdg),            // output buffer
                            &junk,                         // # bytes returned
                            (LPOVERLAPPED) NULL);          // synchronous I/O\

这篇关于如何以编程方式防止DVD弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆