Hi I am making a program to open and close the cd reader in which I have thought to write data to CD, the problem is the basis of the problem, which use "uses Windows 'and' uses MMSystem" but the problem is that when I use both at the same time being "uses Windows, MMSystem" gives an error and the program does not compile, I am using Delphi 2010, the strange thing is that when I use only one either Windows or MMSystem works fine and compiles.
The error when I try to compile is: 'Could not find program'
The code in question is this:
mciSendString ('Set cdaudio door open wait', nil, 0, handle);
I have two things to ask you first is how I avoid the error when using the two (Windows and MMSystem) and the other question was if he could open the CD player without using MMSystem, bone using Windows API, but not where to start
The 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.
Image :
ACCEPTED]
There should be no problem using 'mmsystem' together with 'windows'. Indeed he error in the screen shot in the question does not look like a compiler error. It's rather, the IDE is unable to find the executable. It might be antivirus software perhaps deleting the executable, or I don't know..
In any case, you can use
DeviceIoControl
[1] as an alternative. Here's a Delphi translation of
an answer
[2] on 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;
[1] http://msdn.microsoft.com/en-us/library/windows/desktop/aa363216%28v=vs.85%29.aspxIOCTL_STORAGE_LOAD_MEDIA ($0203) instead of IOCTL_STORAGE_EJECT_MEDIA. - Sertac Akyuz
[dcc32 Error] Unit4.pas(41): E2066 Missing operator or semicolon.. - Ken White