在 2000 下使用所有廠商光碟下控制指令讓 CD 退片正常,有些光碟機在 XP下就無法退片 |
尚未結案
|
fdia
一般會員 發表:4 回覆:12 積分:3 註冊:2002-10-09 發送簡訊給我 |
unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, winioctl; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CloseDevice;
function Lock:boolean;
function UnLock:boolean;
function Eject:Boolean;
private
{ Private declarations }
public
{ Public declarations }
reg: DEVIOCTL_REGISTERS;
hDevice: THandle;
cb: DWORD;
lpFileName: PChar;
pb : packed record
operation, NumLocks : BYTE;
end;
end; const Drive = 'G'; var
Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject);
begin
if Eject then showmessage('Ok');
end; procedure TForm1.Button2Click(Sender: TObject);
begin
if Lock then showmessage('ok');
end; procedure TForm1.Button3Click(Sender: TObject);
begin
if UnLock then showmessage('ok');
end; procedure TForm1.CloseDevice;
begin
CloseHandle(hDevice);
end; function TForm1.Lock;
begin
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
begin
reg.reg_EAX := $440D; //* IOCTL for block devices */
reg.reg_EBX := Ord(UpCase(Drive))-Ord ('A') 1; //* zero-based drive ID */
reg.reg_ECX := MakeWOrd($48,8);
reg.reg_EDX := DWORD(@pb);
pb.operation := 0; if (not Win95IOCTL(@reg)) then
begin
result := FALSE;
exit;
end; if (reg.reg_Flags and $0001) <> 0 then //* error if carry flag set */
begin
result := FALSE;
exit;
end;
Result := True;
end
// Windows NT (4.0 SP3) testing and corrections by Pawel Michalowski
else if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
// Using a variable assignment with lpFileName allows you to debug the
// value you passed as 'Drive'. Usually due to optimization this value
// would be inaccessible. (PM) lpFileName := PChar('\\.\' UpperCase(Drive) ':'); // When getting the device handle in a call to CreateFile you have to
// use GENERIC_READ (0 won't work) and FILE_ATTRIBUTE_NORMAL (again 0
// won't work) (PM) hDevice := CreateFile(lpFileName,
GENERIC_READ{0}, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL{0}, 0); if hDevice = INVALID_HANDLE_VALUE{0} then
begin
Result := False;
showmessage('error hdevice');
Exit;
end;
Result := DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, nil, 0, nil, 0,cb, nil);
CloseHandle(hDevice);
end;
end; function TForm1.UnLock;
begin
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
begin
reg.reg_EAX := $440D; //* IOCTL for block devices */
reg.reg_EBX := Ord(UpCase(Drive))-Ord ('A') 1; //* zero-based drive ID */
reg.reg_ECX := MakeWOrd($48,8);
reg.reg_EDX := DWORD(@pb);
pb.operation := 1;
if (not Win95IOCTL(@reg)) then
begin
result := FALSE;
exit;
end; if (reg.reg_Flags and $0001) <> 0 then //* error if carry flag set */
begin
result := FALSE;
exit;
end;
Result := True;
end
// Windows NT (4.0 SP3) testing and corrections by Pawel Michalowski
else if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
// Using a variable assignment with lpFileName allows you to debug the
// value you passed as 'Drive'. Usually due to optimization this value
// would be inaccessible. (PM) lpFileName := PChar('\\.\' UpperCase(Drive) ':'); // When getting the device handle in a call to CreateFile you have to
// use GENERIC_READ (0 won't work) and FILE_ATTRIBUTE_NORMAL (again 0
// won't work) (PM)
/////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////// 會有可能出在這裡嗎 ???????? ///////////////// hDevice := CreateFile(lpFileName,
GENERIC_READ{0}, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL{0}, 0); if hDevice = INVALID_HANDLE_VALUE{0} then
begin
Result := False;
showmessage('error hdevice');
Exit;
end;
Result := DeviceIoControl(hDevice,
FSCTL_UNLOCK_VOLUME, nil, 0, nil, 0,cb, nil);
CloseHandle(hDevice);
end;
end; function TForm1.Eject;
begin
if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then
begin
reg.reg_EAX := $440D; //* IOCTL for block devices */
reg.reg_EBX := Ord(UpCase(Drive))-Ord ('A') 1; //* zero-based drive ID */
reg.reg_ECX := MakeWOrd($49,8); if (not Win95IOCTL(@reg)) then
begin
result := FALSE;
exit;
end; if (reg.reg_Flags and $0001) <> 0 then //* error if carry flag set */
begin
result := FALSE;
exit;
end;
Result := True;
end
// Windows NT (4.0 SP3) testing and corrections by Pawel Michalowski
else if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
// Using a variable assignment with lpFileName allows you to debug the
// value you passed as 'Drive'. Usually due to optimization this value
// would be inaccessible. (PM) lpFileName := PChar('\\.\' UpperCase(Drive) ':'); // When getting the device handle in a call to CreateFile you have to
// use GENERIC_READ (0 won't work) and FILE_ATTRIBUTE_NORMAL (again 0
// won't work) (PM) hDevice := CreateFile(lpFileName,
GENERIC_READ{0}, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL{0}, 0); if hDevice = INVALID_HANDLE_VALUE{0} then
begin
Result := False;
Exit;
end;
Result := DeviceIoControl(hDevice,
IOCTL_DISK_EJECT_MEDIA , nil, 0,
nil,0, cb, nil); CloseHandle(hDevice);
end;
end; end. I Love Sony
------
I Love Sony |
fdia
一般會員 發表:4 回覆:12 積分:3 註冊:2002-10-09 發送簡訊給我 |
|
fdia
一般會員 發表:4 回覆:12 積分:3 註冊:2002-10-09 發送簡訊給我 |
|
airs
一般會員 發表:7 回覆:4 積分:2 註冊:2002-08-30 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |