Для того, чтобы открыть сидюк на с++ и таким же образом его закрыть нам пригодится приведенный ниже код.
Открываем:
#include <windows.h>
#pragma hdrstop
#pragma argsused
...
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);
}
}
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
CD_OpenCloseDrive(TRUE, 'D');
exit(1);
}
Закрываем:
#include <windows.h>
#pragma hdrstop
#pragma argsused
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);
}
}
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
CD_OpenCloseDrive(FALSE, 'D');
exit(1);
}
Все исходники можно скачать.
Написать комментарий