L
landina
Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码为什么会返回错误:5?<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Label1: TLabel;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br> PPARTITION_INFORMATION=^PARTITION_INFORMATION;<br> PARTITION_INFORMATION = RECORD<br> StartingOffset: TLargeInteger;<br> PartitionLength: TLargeInteger;<br> HiddenSectors: DWORD;<br> PartitionNumber: DWORD;<br> PartitionType: BYTE;<br> BootIndicator: WordBool;<br> RecognizedPartition: WordBool;<br> RewritePartition: WordBool;<br> end;<br><br> PDRIVE_LAYOUT_INFORMATION=^DRIVE_LAYOUT_INFORMATION;<br> DRIVE_LAYOUT_INFORMATION = Record<br> PartitionCount : DWORD;<br> Signature : DWORD;<br> Partitioninfo: array[0..1] of PARTITION_INFORMATION;<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>Function GetDiskGeometry(DriveNum : Longint) : PARTITION_INFORMATION;<br>Var<br> RetBytes : DWORD;<br> hDevice : Longint;<br> Status : Longbool;<br> Drive : String;<br> Layout : DRIVE_LAYOUT_INFORMATION;<br> Size : Integer;<br> Success: Boolean;<br>begin<br> Drive := '//./PhysicalDrive' + inttostr(DriveNum);<br><br> FillChar(Layout,SizeOf(DRIVE_LAYOUT_INFORMATION),0);<br> RetBytes := 0;<br><br> hDevice := CreateFile(PChar(Drive),0, FILE_SHARE_READ Or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);<br><br><br> If hDevice <> INVALID_HANDLE_VALUE Then<br> begin<br><br> Status := DeviceIoControl(hDevice, 475148,nil, 0, @Layout, Sizeof(DRIVE_LAYOUT_INFORMATION), RetBytes, nil);<br> if (status = false) then<br> showmessage('Failed : '+inttostr(getLastError()));<br> showmessage(inttostr(Layout.PartitionCount));<br> CloseHandle(hDevice);<br> end;<br>End;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> layout: PARTITION_INFORMATION;<br>begin<br> layout := GetDiskGeometry(1);<br><br>end;<br><br>end.