#include <windows.h>
#define OPEN_CDROM MCI_SET_DOOR_CLOSED
#define CLOSE_CDROM MCI_SET_DOOR_OPEN
void CD_OpenCloseDrive(BOOL bOpenDrive,TCHAR cDrive)
{
/* bOpenDrive is a boolean value containing whether the drive should be opened or closed. cDrive is a TCHAR which contains the specific drive letter to be used. If no letter is passed, then the first CD drive in the MCI device list will be used.
The function opens or closes the appropriate CD drive based on its arguments
*/
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;
//set the flags for the device type
flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID |
MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
}
else
{
// set the flags for the device type
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) // decides whether to open or close
{
// open drive
mciSendCommand
(op.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
}
else
{
// close drive
mciSendCommand
(op.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
}
// release access to the device
mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
}
}
int main()
{
TCHAR new_letter = 'O'; //CDROM drive letter
CD_OpenCloseDrive(TRUE, new_letter);
Sleep(1000);
CD_OpenCloseDrive(FALSE, new_letter);
return 0;
}
Husk at tilføje biblioteket 'libwinmm.a' for at kunne kompilere koden.
Med venlig hilsen
Mads Nielsen
Syntes ikke rigtigt jeg kan få det til at virke, tror det er det bibliotek som jeg skal tilføje, for den siger samme fejl selv om jeg prøver at tilføje den eller ej.
Den giver dene fejlmeddelselse: MCI_OPEN_PARMS' undeclared (first use this function)
og så en masse andre bagefter selvfølgelig
kunne være rart hvis du lige skriv hvordan jeg tilføjer det bibliotek
Er meget ny til C++ så jeg gør nok noget forkert :/