Originally posted by waldis
Thanx! It compiled as soon as I added the winmm.lib.
Persoanlly I dont use this to open the CDROM.......you find that if you have 2 drives (as I do - 1 CDRW, 1 DVD), then you might want control over one of them.
If you have WinNT or above, you can use CreateFile to open a handle the drive (as a device - not just a disk). Then you can control each device seperately
For instance I have E drive and D Drive as CDROMs
Code:
#include <windows.h>
#include <winioctl.h>
int main()
{
HANDLE hD = 0,
hE = 0;
enum DRIVE_{D_DRIVE = 0,E_DRIVE} e_drive = D_DRIVE;
DWORD dwDummy;
hD = CreateFile("\\\\.\\D:",GENERIC_READ,0,0,OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,0);
hE = CreateFile("\\\\.\\E:",GENERIC_READ,0,0,OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,0);
if(hD != INVALID_HANDLE_VALUE && hE != INVALID_HANDLE_VALUE)
{
for(int i = 0;i < 6;++i)
{
DeviceIoControl((e_drive ? hE : hD),
IOCTL_STORAGE_EJECT_MEDIA ,0,0,0,0,&dwDummy,0);
Sleep(3000);
DeviceIoControl((e_drive ? hE : hD),
IOCTL_STORAGE_LOAD_MEDIA,0,0,0,0,&dwDummy,0);
Sleep(3000);
e_drive = (e_drive ? D_DRIVE : E_DRIVE);
}
}
if(hD)CloseHandle(hD);
if(hE)CloseHandle(hE);
return 0;
}