Using Windows and MMS in Delphi

Hi, I am making a program to open and close a CD reader, in which I thought to write data to a CD, the problem is the basis of the problem that uses “uses Windows” and “uses MMSystem”, but the problem is that, when I use both at the same time, "uses Windows, MMSystem" gives an error, and the program does not compile, I use Delphi 2010, the strange thing is that when I use only one, either Windows or the MMS system works fine and compiles.

Error trying to compile: "Could not find program"

The code in question is:

mciSendString ('Set cdaudio door open wait', nil, 0, handle);

I have two things I want to ask, firstly, how can I avoid the error when using two (Windows and MMSystem), and another question was whether it could open a CD player without using MMSystem, bone using the Windows API but not where to start

Source:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Windows,MMSystem;

procedure opencd;
begin
  mciSendString('Set cdaudio door open wait', nil, 0, 0);
end;

begin
  try
    Writeln('test');
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Picture:

test

+4
source share
1 answer

There should be no problem using "mmsystem" with "windows". Indeed, the error in the screen shot in the question is not like a compiler error. Rather, the IDE cannot find the executable. Perhaps the antivirus software may delete the executable file, or I don’t know ..

DeviceIoControl . Delphi SO:

function CtlCode(DeviceType, _Function, Method, Access: Integer): DWORD;
begin
  Result := DeviceType shl 16 or Access shl 14 or _Function shl 2 or Method;
end;

procedure ejectDisk(driveLetter: Char);
const
  FILE_DEVICE_FILE_SYSTEM = $00000009;
  FILE_DEVICE_MASS_STORAGE = $0000002d;
  METHOD_BUFFERED = 0;
  FILE_ANY_ACCESS = 0;
  FILE_READ_ACCESS = $0001;
  IOCTL_STORAGE_BASE = FILE_DEVICE_MASS_STORAGE;
// bogus constants below, rather CTL_CODEs should be pre computed.
  FSCTL_LOCK_VOLUME = 6;
  FSCTL_DISMOUNT_VOLUME = 8;
  IOCTL_STORAGE_EJECT_MEDIA = $0202;
var
  tmp: string;
  handle: THandle;
  BytesReturned: DWORD;
begin
  tmp := Format('\\.\%s:', [driveLetter]);
  handle := CreateFile(PChar(tmp), GENERIC_READ, FILE_SHARE_WRITE, nil,
      OPEN_EXISTING, 0, 0);
  DeviceIoControl(handle,
      CtlCode(FILE_DEVICE_FILE_SYSTEM, FSCTL_LOCK_VOLUME, METHOD_BUFFERED,
      FILE_ANY_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
  DeviceIoControl(handle,
      CtlCode(FILE_DEVICE_FILE_SYSTEM, FSCTL_DISMOUNT_VOLUME, METHOD_BUFFERED,
      FILE_ANY_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
  DeviceIoControl(handle,
      CtlCode(IOCTL_STORAGE_BASE, IOCTL_STORAGE_EJECT_MEDIA, METHOD_BUFFERED,
      FILE_READ_ACCESS), nil, 0, nil, 0, BytesReturned, nil);
  CloseHandle(handle);
end;
+4

All Articles