USB Dismount not turning off my USB Drive?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 5
Reputation: AntiBNI is an unknown quantity at this point 
Solved Threads: 0
AntiBNI AntiBNI is offline Offline
Newbie Poster

USB Dismount not turning off my USB Drive?

 
0
  #1
Dec 8th, 2008
I'm making an app that needs to safely remove USB Drives and SD cards.

When i execute my code,the drive gets forced not to be ready.

I have an old 128MB usb drive and when i start transferring data to it and execute my code,a msg box pops up saying: USB Cannot copy to "FileName" Device not ready.

And also,when i execute the code the drive stays visible in the pc and can be accessed again without having to replug.

Is that normal?
Am i doing some thing wrong?
Am i missing something?
Heres my code:

  1. HANDLE File;
  2. DWORD BytesReturned;
  3. char DrivePath[MAX_PATH] = "\\\\.\\J:";
  4. File = CreateFile(DrivePath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
  5. DeviceIoControl(File,FSCTL_LOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
  6. DeviceIoControl(File,FSCTL_DISMOUNT_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
  7. DeviceIoControl(File,IOCTL_STORAGE_MEDIA_REMOVAL,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
  8. DeviceIoControl(File,FSCTL_UNLOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
  9. CloseHandle(File);
  10. if(&BytesReturned == 0)
  11. MessageBox("The Drive Could Not be Removed,Is being used by an app or has not finished an operation","Note",MB_OK);
  12. else
  13. MessageBox("You can now remove the USB Drive","Removed",MB_OK);

Help will be greatly appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 5
Reputation: AntiBNI is an unknown quantity at this point 
Solved Threads: 0
AntiBNI AntiBNI is offline Offline
Newbie Poster

Re: USB Dismount not turning off my USB Drive?

 
0
  #2
Dec 8th, 2008
Is Disabling the drive while is being in a read/write process dangerous?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC