library ctlcdrom;<br><br>uses<br> Windows, MMSystem;<br><br>{$R *.res}<br><br>type<br> TCDRomOperate = (cdOpen, cdClose);<br> TCDStatus = (csOpen, csClosed);<br><br>function OperateCDROM(DriveLetter: Char; Operate: TCDRomOperate): Boolean;<br>var<br> OpenParm: TMCI_OPEN_Parms;<br> Flags: DWORD;<br> Drive: string;<br> DeviceID: Word;<br> Err: Cardinal;<br>begin<br> Drive := DriveLetter + ':';<br> Flags := mci_Open_Type or mci_Open_Element;<br> with OpenParm do<br> begin<br> dwCallBack := 0;<br> lpstrDeviceType := 'CDAudio';<br> lpstrElementName := PChar(Drive);<br> end;<br> Result := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm)) = 0;<br> if Result then<br> begin<br> DeviceID := OpenParm.wDeviceID;<br> try<br> case Operate of<br> cdOpen :<br> Result := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0) = 0;<br> cdClose:<br> Result := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0) = 0;<br> end;<br> finally<br> mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));<br> end;<br> end;<br>end;<br><br>function OpenCDROM(Drive: Char): Boolean; stdcall; // 打开CDROM<br>begin<br> Result := OperateCDROM(Drive, cdOpen);<br>end;<br><br>function CloseCDROM(Drive: Char): Boolean; stdcall; // 关闭CDROM<br>begin<br> Result := OperateCDROM(Drive, cdClose);<br>end;<br><br>exports //dll文件导出的函数列表<br> OpenCDROM,<br> CloseCDROM;<br><br>begin<br>end.