CD drive open and close
-
hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:
-
hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:
-
-
thanks sir but actually i have no idea about this so can u give me some other example for help thanks
p_ wrote:
so can u give me some other example for help
But the sample is already there in the link I provide. The cd drive can be ejected and inserted using the DeviceIoControl() function. For eg if you want to eject the drive the below code will do DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_STORAGE_EJECT_MEDIA, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); And for inserting change the flag to IOCTL_STORAGE_LOAD_MEDIA
nave [OpenedFileFinder]
-
p_ wrote:
so can u give me some other example for help
But the sample is already there in the link I provide. The cd drive can be ejected and inserted using the DeviceIoControl() function. For eg if you want to eject the drive the below code will do DeviceIoControl( (HANDLE) hDevice, // handle to device IOCTL_STORAGE_EJECT_MEDIA, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); And for inserting change the flag to IOCTL_STORAGE_LOAD_MEDIA
nave [OpenedFileFinder]
-
sir i use this code on button but it does not work DWORD bytesreturned; DWORD IOCTL_STORAGE_EJECT_MEDIA; void * hDevice; DeviceIoControl( hDevice, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL ); thanks
p_ wrote:
void * hDevice;
Now you are passing an invalid value as hDevice. see the below code in the above link.
HANDLE OpenVolume(TCHAR cDriveLetter) { HANDLE hVolume; UINT uDriveType; TCHAR szVolumeName[8]; TCHAR szRootName[5]; DWORD dwAccessFlags; wsprintf(szRootName, szRootFormat, cDriveLetter); uDriveType = GetDriveType(szRootName); switch(uDriveType) { case DRIVE_REMOVABLE: dwAccessFlags = GENERIC_READ | GENERIC_WRITE; break; case DRIVE_CDROM: dwAccessFlags = GENERIC_READ; break; default: _tprintf(TEXT("Cannot eject. Drive type is incorrect.\n")); return INVALID_HANDLE_VALUE; } wsprintf(szVolumeName, szVolumeFormat, cDriveLetter); hVolume = CreateFile( szVolumeName, dwAccessFlags, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); if (hVolume == INVALID_HANDLE_VALUE) ReportError(TEXT("CreateFile")); return hVolume; }
If you specify the drive letter of the drive, te above function will return a handle pass that handle to the DeviceIoControl() function. likeHANDLE hVolume = OpenVolume( "E:" ); OpenVolume( hVolume, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &bytesreturned, NULL );
nave [OpenedFileFinder]
-
hi to all vc++ masters and happy teachers day :rose: i am building an application in which there is button and i want that when i clich on that button the CD:Drive open and when i click on another button CD:Drive closed please help me in this regard and i have no idea about that thanks :rose:
Try
mciSendCommand()
, like:mciSendCommand(..., MCI_SET, MCI_SET_DOOR_OPEN, ...);
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne