弹出闪光灯 [英] Ejecting a flash

查看:100
本文介绍了弹出闪光灯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想在 MFC 中弹出闪光灯,我使用方法EjectDiskFromSADrive,但始终会收到错误 87 .

Hi there
I want to eject a flash in MFC, I use method EjectDiskFromSADrive but it always get the error 87.

EjectDiskFromSADrive(null, this.Name, PhysicalDrivePath, this.Handle, "Eject flash?", "Eject flash?", (Int32)0);



请帮帮我.
非常感谢.
最佳



please help me.
thanks a lot.
Best

推荐答案

如果通过弹出闪存"来表示准备 USB 驱动器以安全移除",请参见
If by "Ejecting a flash" you mean "Preparing a USB drive for safe removal" see this[^] useful CodeProject article. :)


您可以在codeproject.com上查看此文章

使用C#弹出USB磁盘 [
You could look at this article on the codeproject.com

Eject USB disks using C#[^]

Also, be aware that this function is obsolete since Windows Server 2008 R2 and Windows Vista R2 (Sold as separate OS instead of an update and better known as Windows 7)

Good luck!


感谢您的回答.它对我很有帮助.
但是我面临另一个问题,有时我的代码无法识别闪光灯.我的代码是:
LRESULT CMCCDlg :: OnDevChange(WPARAM wParam,LPARAM lParam)
{
DEV_BROADCAST_HDR * pHDR =(DEV_BROADCAST_HDR *)lParam;
开关(wParam){
案例DBT_USERDEFINED:
TRACE("a \ n");
休息;
案例DBT_QUERYCHANGECONFIG:
TRACE("b \ n");
休息;
案例DBT_DEVNODES_CHANGED:
TRACE("n \ n");
休息;
案例DBT_DEVICETYPESPECIFIC:
TRACE("m \ n");
休息;
案例DBT_DEVICEREMOVEPENDING:
TRACE("j \ n");
休息;
案例DBT_DEVICEREMOVECOMPLETE:
m_Repository.m_FlashMemoryInf.ConnectionFlag = FALSE;
TRACE("k \ n");
休息;
大小写DBT_DEVICEQUERYREMOVEFAILED:
TRACE("l \ n");
休息;
案例DBT_DEVICEQUERYREMOVE:
TRACE("er \ n");
休息;
案例DBT_DEVICEARRIVAL:
休息;
案例DBT_CONFIGCHANGED:
TRACE("o \ n");
休息;
案例DBT_CONFIGCHANGECANCELED:
TRACE("i \ n");
休息;
}
如果(pHDR){
开关(pHDR-> dbch_devicetype){
案例DBT_DEVTYP_OEM:
休息;
案例DBT_DEVTYP_PORT:
休息;
案例DBT_DEVTYP_VOLUME:
for(int drive = 1; drive< 32; drive ++){
char szDrvName [100];
_stprintf(szDrvName,_T(%c:\\"),``A''+ drive);
开关(GetDriveType(szDrvName))
{
情况0://无法确定驱动器类型.
情况1://根目录不存在.
休息;
case DRIVE_REMOVABLE://可以从驱动器中卸下驱动器.
sprintf(m_Repository.m_FlashMemoryInf.DriveName,%s",szDrvName);
m_Repository.m_FlashMemoryInf.ConnectionFlag = TRUE;
休息;
case DRIVE_CDROM://该驱动器是CD-ROM驱动器.
休息;
case DRIVE_FIXED://无法从驱动器中删除磁盘.
休息;
case DRIVE_REMOTE://该驱动器是远程(网络)驱动器.
休息;
case DRIVE_RAMDISK://驱动器是RAM磁盘.
休息;

但是当它不知道闪光灯总是等待时
案例DBT_DEVNODES_CHANGED
和switch(pHDR)从不执行.
为什么会发生?
非常感谢
thanks for your answer.it helped me alot.
But I face to another problem,sometimes my code doesn''t recognize a flash.my code is:
LRESULT CMCCDlg::OnDevChange(WPARAM wParam, LPARAM lParam)
{
DEV_BROADCAST_HDR* pHDR=(DEV_BROADCAST_HDR*)lParam;
switch(wParam) {
case DBT_USERDEFINED:
TRACE("a\n");
break;
case DBT_QUERYCHANGECONFIG:
TRACE("b\n");
break;
case DBT_DEVNODES_CHANGED:
TRACE("n\n");
break;
case DBT_DEVICETYPESPECIFIC:
TRACE("m\n");
break;
case DBT_DEVICEREMOVEPENDING:
TRACE("j\n");
break;
case DBT_DEVICEREMOVECOMPLETE:
m_Repository.m_FlashMemoryInf.ConnectionFlag=FALSE;
TRACE("k\n");
break;
case DBT_DEVICEQUERYREMOVEFAILED:
TRACE("l\n");
break;
case DBT_DEVICEQUERYREMOVE:
TRACE("er\n");
break;
case DBT_DEVICEARRIVAL:
break;
case DBT_CONFIGCHANGED:
TRACE("o\n");
break;
case DBT_CONFIGCHANGECANCELED:
TRACE("i\n");
break;
}
if (pHDR) {
switch(pHDR->dbch_devicetype) {
case DBT_DEVTYP_OEM:
break;
case DBT_DEVTYP_PORT:
break;
case DBT_DEVTYP_VOLUME:
for (int drive=1;drive<32;drive++) {
char szDrvName[100];
_stprintf( szDrvName, _T("%c:\\"), ''A''+drive );
switch ( GetDriveType( szDrvName ) )
{
case 0: // The drive type cannot be determined.
case 1: // The root directory does not exist.
break;
case DRIVE_REMOVABLE: // The drive can be removed from the drive.
sprintf(m_Repository.m_FlashMemoryInf.DriveName,"%s",szDrvName);
m_Repository.m_FlashMemoryInf.ConnectionFlag=TRUE;
break;
case DRIVE_CDROM: // The drive is a CD-ROM drive.
break;
case DRIVE_FIXED: // The disk cannot be removed from the drive.
break;
case DRIVE_REMOTE: // The drive is a remote (network) drive.
break;
case DRIVE_RAMDISK: // The drive is a RAM disk.
break;

but when it doesn''t know the flash always wait on
case DBT_DEVNODES_CHANGED
and switch(pHDR) never execute.
why does it happen?
thanks alot


这篇关于弹出闪光灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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