1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function OpenCD(Drive: String): Boolean;
var
OpenParm: TMCI_Open_Parms;
Flags: DWord;
DeviceID : Word;
Error: MciError;
ErrorText: PChar;
LenghtBuffer: Cardinal;
begin
Result := False;
LenghtBuffer := 255; // !
try // !
GetMem(ErrorText, LenghtBuffer); // !
Flags := mci_Open_Type or mci_Open_Element;
with OpenParm do begin
dwCallback := 0;
lpstrDeviceType := 'CDAudio';
lpstrElementName := PChar(Copy(Drive, 0, 2));
end;
Error := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));
mciGetErrorString(Error, ErrorText, LenghtBuffer);
if Error = 0 then
DeviceID := OpenParm.wDeviceID
else
raise EAccessViolation.Create(ErrorText);
try
Error := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
mciGetErrorString(Error, ErrorText, LenghtBuffer);
finally
mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));
end;
if Error = 0 then
Result := True
else
raise EAccessViolation.Create(ErrorText);
finally // !
FreeMem(ErrorText, LenghtBuffer); // !
end; // !
end; |
Partager