function TCDROMCtrl.CloseCDRom(Drive: char): boolean;
var //if run successful then
return TRUE
Drive which cdrom you want to close
res:mcierror;
openparm:TMCI_Open_Parms;
flags:dword;
s:string;
deviceid:word;
begin
result:=true;
s:=drive+':';
flags:=mci_open_type or mci_open_element;
with openparmdo
begin
dwcallback:=0;
lpstrdevicetype:='CDAudio';
lpstrelementname:=pchar(s);
end;
res:=mcisendcommand(0,mci_open,flags,longint(@openparm));
if res <> 0 then
exit;
deviceID:=openparm.wdeviceid;
try
res:=mcisendcommand(deviceid,mci_set,mci_set_door_closed,0);
if res = 0 then
exit;
result:=false;
finally
mcisendcommand(deviceid,mci_close,flags,longint(@openparm));
end;
end;
function TCDROMCtrl.OpenCDRom(Drive: char): boolean;
var
res:mcierror;
openparm:TMCI_Open_Parms;
flags:dword;
s:string;
deviceid:word;
begin
result:=true;
s:=drive+':';
flags:=mci_open_type or mci_open_element;
with openparmdo
begin
dwcallback:=0;
lpstrdevicetype:='CDAudio';
lpstrelementname:=pchar(s);
end;
res:=mcisendcommand(0,mci_open,flags,longint(@openparm));
if res <> 0 then
exit;
deviceID:=openparm.wdeviceid;
try
res:=mcisendcommand(deviceid,mci_set,mci_set_door_open,0);
if res = 0 then
exit;
result:=false;
finally
mcisendcommand(deviceid,mci_close,flags,longint(@openparm));
end;
end;