is there any tutorial that explains how eject cdrom? can you help me thanks
Printable View
is there any tutorial that explains how eject cdrom? can you help me thanks
The mciSendString is a good way to open a cdrom.......you can find examples on this board if you look..... dont forget the winmm.lib when linking...
Also the DeviceIoControl() API can open these drives....
Here's something I was messing with a while back..its not as good as using mciSendString(), but it kept me entertained for a little while :).........it works on Win2000 and probably therefore XP, but I dont think it will work on Win98.....anyway...it uses an API to give a bitmask of all drives available, and then tests them to see if they are CDROMs....then it opens a handle to the drive (I think this is where it would fail with Win98) and uses DeviceIoControl() to open the drive. Its not very good, but I thought I'd post it anyway :) ...have a look
Code:
#include <windows.h>
#include <winioctl.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
DWORD dwDriveMask,
dwMaskPos = 0,
dwCountByte;
string str,
temp;
char ch;
HANDLE hDrive;
str = "";
dwDriveMask = GetLogicalDrives();
if(!dwDriveMask){
cout << "Error";
return 1;
}
while(dwDriveMask > 0
&& dwMaskPos < 26){
if(dwDriveMask & 1){
temp += (char)dwMaskPos + 65;
temp += ":\\";
if(GetDriveType(temp.c_str()) == DRIVE_CDROM){
str += (char)dwMaskPos + 65;
}
temp = "";
}
dwDriveMask >>= 1;
dwMaskPos++;
}
cout << "Available CD drives" << endl;
for(int i = 0; i < str.length();i++)
cout << str[i] << " ";
while (1){
cout << endl << "Choose drive letter";
cout << " to open that drive's tray, 0 to exit" << endl;
cin >> ch;
if(ch == '0')
break;
temp = "\\\\.\\";
temp += ch;
temp += ":";
hDrive = CreateFile(temp.c_str(),GENERIC_READ,
NULL,NULL,OPEN_EXISTING,NULL,NULL);
if(hDrive==INVALID_HANDLE_VALUE){
cout << "Error";
return 1;
}
DeviceIoControl(hDrive,IOCTL_STORAGE_EJECT_MEDIA,NULL,
NULL,NULL,NULL,&dwCountByte,NULL);
CloseHandle(hDrive);
temp = "";
}
return 0;
}
That's sweet!! haha!! Why is it the stupid stuff that makes me so damn happy?
I dunno, but bumping threads makes me unhappy