• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

Eject CD-ROM

Hello,

Does anybody know the command that is used in VC++ to eject the CD-ROM?

Thank you all
0
Mazen
Asked:
Mazen
1 Solution
 
jkrCommented:
See http://www.codeguru.com/system/cdr.html

//Open or Close CD Drive
//cDrive is Drive Letter to Open, or 0x01 for 'Default' drive
//Examples:
//CD_OpenCloseDrive(TRUE, 'G');  //Open CD Door for Drive G:
//CD_OpenCloseDrive(FALSE, 'G'); //Close CD Door for Drive G:
//CD_OpenCloseDrive(TRUE, 1);    //Open First Logical CD Door
void CD_OpenCloseDrive(BOOL bOpenDrive, TCHAR cDrive)
{
MCI_OPEN_PARMS op;
MCI_STATUS_PARMS st;
DWORD flags;

TCHAR szDriveName[4];
strcpy(szDriveName, "X:");

::ZeroMemory(&op, sizeof(MCI_OPEN_PARMS));
op.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO;

if(cDrive > 1)
{
 szDriveName[0] = cDrive;
 op.lpstrElementName = szDriveName;
 flags = MCI_OPEN_TYPE
       | MCI_OPEN_TYPE_ID
       | MCI_OPEN_ELEMENT
       | MCI_OPEN_SHAREABLE;
}
else flags = MCI_OPEN_TYPE
           | MCI_OPEN_TYPE_ID
           | MCI_OPEN_SHAREABLE;

if (!mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&op))
{
 st.dwItem = MCI_STATUS_READY;

 if(bOpenDrive)
  mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
 else
  mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);

 mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
}
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now