| | |
USB Dismount not turning off my USB Drive?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
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:
Help will be greatly appreciated.
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:
C++ Syntax (Toggle Plain Text)
HANDLE File; DWORD BytesReturned; char DrivePath[MAX_PATH] = "\\\\.\\J:"; File = CreateFile(DrivePath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); DeviceIoControl(File,FSCTL_LOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL); DeviceIoControl(File,FSCTL_DISMOUNT_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL); DeviceIoControl(File,IOCTL_STORAGE_MEDIA_REMOVAL,NULL,NULL,NULL,NULL,&BytesReturned,NULL); DeviceIoControl(File,FSCTL_UNLOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL); CloseHandle(File); if(&BytesReturned == 0) MessageBox("The Drive Could Not be Removed,Is being used by an app or has not finished an operation","Note",MB_OK); else MessageBox("You can now remove the USB Drive","Removed",MB_OK);
Help will be greatly appreciated.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Getting happy face value instead of O for tic tac toe prog.
- Next Thread: stuck on c++ assignment
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





