Click here to Skip to main content
15,937,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there
I want to eject a flash in MFC, I use method EjectDiskFromSADrive but it always get the error 87.

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


please help me.
thanks a lot.
Best
Posted
Updated 27-Jul-10 23:55pm
v2

If by "Ejecting a flash" you mean "Preparing a USB drive for safe removal" see this[^] useful CodeProject article. :)
 
Share this answer
 
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!
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900