G
G
German2018-06-07 21:09:17
C++ / C#
German, 2018-06-07 21:09:17

How to open and close DVD-RW drive?

Wrote this code

#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <mmsystem.h>

using namespace std;

int main()
{
  MCI_OPEN_PARMS OpenParm;
  MCI_SET_PARMS SetParm;
  MCIDEVICEID dID;
  OpenParm.lpstrDeviceType=L"CDAudio";
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, (DWORD_PTR)&OpenParm);
  dID = OpenParm.wDeviceID;
  mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD_PTR)&SetParm);
  Sleep(3000);
  mciSendCommand(dID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR)&SetParm);
  mciSendCommand(dID, MCI_CLOSE, MCI_NOTIFY, (DWORD_PTR)&SetParm);
  return 0;
}

But the problem is that he is trying to work with a CD (there is a modem that reacts to this), and I have a DVD-RW.
5b1974aa39ff9407201695.png
What to specify instead of CDAudio?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
alexalexes, 2018-06-07
@mrjbom

You need to bind to the device not only by its type, but also by the drive letter.
Opening:

mciSendString("open f: type cdaudio alias cd", NULL, 0, NULL);
mciSendString("set cd door open wait", NULL, 0, NULL);

Closure:
mciSendString("open f: type cdaudio alias cd", NULL, 0, NULL);
mciSendString("set cd door closed wait", NULL, 0, NULL);

S
Sumor, 2018-06-07
@Sumor

Try

OpenParm.lpstrDeviceType = L"F:";
OpenParm.lpstrDeviceType=L"CDAudio";
mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD_PTR)&OpenParm);

G
German, 2018-06-09
@mrjbom

5b1bec46c01a8655629133.png
This code causes the application to crash after launch.
What's wrong?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question