function GetDevice : word;
var
OpenParms : TMCI_Open_Parms;
MyErrorString : array[0..MAXERRORLENGTH - 1] of Char;
fErrCode:longint;
FFlags:dword;
ss: string;
begin
Result:=0;
FFlags := mci_notify or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
OpenParms.dwCallback := 0;
ss := DriverPath+'/track 1.cda';//DriverPath 你想控制的光驱的盘符,如I:
OpenParms.lpstrElementName := PChar(ss);
fErrCode := mciSendCommand(0, mci_open, FFlags, Longint(@OpenParms));
if FErrCode = 0 then
{device successfully opened}
begin
Result := OpenParms.wDeviceID;
end
else
begin
MciGetErrorString(FErrCode,MyErrorString,MAXERRORLENGTH - 1);
Showmessage(MyErrorString);
end;
end;
function OpenDoor(Open: Boolean): boolean;
var
SetParms: TMCI_Set_Parms;
GenParm: TMCI_Generic_Parms;
fErrCode:longint;
FFlags:dword;
did:dword;
MyErrorString : array[0..MAXERRORLENGTH - 1] of Char;
begin
if Open then
FFlags := mci_notify or mci_set_door_open
else
FFlags := mci_notify or mci_set_door_Closed;
do
orOpen := Open;
SetParms.dwCallback := 0;
did:=GetDevice;
fErrCode := mciSendCommand(did, mci_Set, FFlags, Longint(@SetParms));
if fErrCode=0 then
result:=true
else
result:=false;
FFlags := 0;
GenParm.dwCallback := 0;
fErrCode := mciSendCommand( did, mci_Close, FFlags, Longint(@GenParm));
if FErrCode <> 0 then
{device successfully opened}
begin
MciGetErrorString(FErrCode,MyErrorString,MAXERRORLENGTH - 1);
Showmessage(MyErrorString);
end;
end;