读取2g内的数据正常,超过2g的部分就出错,个人感觉是FileRead出的问题。请高手指点一二。
const
BytesPerSector =512;
SectorCount =3;
SectorStart =5000000;  //(这里超过2g,4194304以上,就读成0扇区,2g内正常。
drive ='\\.\PHYSICALDRIVE0';
procedure TForm1.Button1Click(Sender: TObject);
var
str :string;
p :pchar;
i :Cardinal;
hDeviceHandle :Thandle;
i2:int64;
begin
hDeviceHandle := CreateFile(drive, GENERIC_READ,
FILE_SHARE_READ OR FILE_SHARE_WRITE, nil, OPEN_EXISTING,0, 0);
if (hDeviceHandle <> INVALID_HANDLE_VALUE) then
begin
p:=allocmem(SectorCount*BytesPerSector);
i2:=  int64(SectorStart)*int64(BytesPerSector);
FileSeek(hDevicehandle,i2,0);
if FileRead(hDevicehandle,p[0],SectorCount*BytesPerSector)<>SectorCount*BytesPerSector then
raise exception.create('读取错误');str:='';
for i:=0 to 512-1 do
begin
if i mod 16=0 then
str:=str+format('0x%.8x ',[i]);
str:=str+format(' %.2x',[integer(p[i])]);
if i mod 16=15 then
str:=str+#13#10;
end;
memo1.Lines.Clear;
memo1.Lines.Add(str);freemem(p,SectorCount*BytesPerSector);
closehandle(hDeviceHandle);
end;
end;