|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (6 bit)
Join Date: Jun 2001
Location: My house
Posts: 62
|
Hi i'm really new to c++ (i can only do basic stuff so far) but i was wondering if there was somehow a way to make a program open your cd tray???
|
|
|
|
|
|
#2 |
|
Member (10 bit)
|
The program is actually quite simple once you understand the code. Try this..
#include void __fastcall Open() { DWORD bytes; HANDLE hDevice = CreateFile("\\\\.\\D:", GENERIC_READ, FILE_SHARE_READ , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); DeviceIoControl(hDevice,IOCTL_DISK_EJECT_MEDIA,NULL,0, NULL, 0, &bytes, (LPOVERLAPPED) NULL); CloseHandle(hDevice); } void __fastcall Close() { DWORD bytes; HANDLE hDevice = CreateFile("\\\\.\\D:", GENERIC_READ, FILE_SHARE_READ , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); DeviceIoControl(hDevice,IOCTL_DISK_LOAD_MEDIA,NULL,0, NULL, 0, &bytes, (LPOVERLAPPED) NULL); CloseHandle(hDevice); } |
|
|
|
|
|
#3 |
|
SQL nutcase
|
Euh, not every CD Drive is Drive D.
|
|
|
|
|
|
#4 |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
Yeah, if you wanted to open a CD, you need to decide to get the drive letter by:
a) A registry value, saved after you query the user as to the CD drive they prefer -or- b) Enumerate the drives and check each drive's type (and then open ALL CDROM drives) -or- c) Same as b), but open only the first CDROM -or- d) Hardcode the letter (not recommended for a program you're distributing, but easiest for your own use). If you're installing the program from a CD initially, it's easy to simply use the letter of the drive they installed from.
__________________
Paul M. Victorey ------------------ I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk. |
|
|
|
|
|
#5 |
|
SQL nutcase
|
I think the best way to do it is enumerate the cd drives, and query the user if there is more than one drive.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|