FileHandle = CreateFile_(FileName$, $40000000 | $80000000, 3, 0, 3, 0, 0)
If FileHandle >0
;====== 讀取資源檔案的頭部資訊
FileSize = FileSize(FileName$)
ReadSize = $110
*MemoryID = AllocateMemory(ReadSize)
Paddess = SetFilePointer_(FileHandle, 0, 0, 0) ;獲取資源檔案起始地址的指標
ReadFile_(FileHandle, *MemoryID, ReadSize, @Paddess, 0) ;加載資源檔案
;====== 獲取關鍵的資源檔案資訊
_FileCount = PeekL(*MemoryID + $104) ;檔案的數量
Pos = PeekL(*MemoryID + $108) ;檔案索引的起始位置
;====== 加載資源檔案索引部分的內容
FileSize = FileSize - Pos
*MemoryID = ReAllocateMemory(*MemoryID, FileSize)
Paddess = SetFilePointer_(FileHandle, Pos, 0, 0) ;獲取資源檔案起始地址的指標
ReadFile_(FileHandle, *MemoryID, FileSize, @Paddess, 0) ;加載資源檔案
;====== 關閉資源檔案
CloseHandle_(FileHandle)
請問這段用PureBasic寫的代碼轉換成pascal是不是下面這樣
var
FileHandle:DWORD;
FileSize:DWORD;
ReadSize:DWORD;
MemoryID:Pointer;
Paddress:DWORD;
FileCount:DWORD;
Pos:DWORD;
begin
if OpenDialog1.Execute then
begin
FileHandle:=CreateFile(PChar(OpenDialog1.FileName),
$40000000 or $80000000,
3,
nil,
3,
0,
0);
if FileHandle > 0 then
begin
FileSize:=length(OpenDialog1.FileName);
ReadSize:=$110;
MemoryID:=AllocMem(ReadSize);
Paddress:=SetFilePointer(FileHandle,
0,
nil,
0);
ReadFile(FileHandle,
MemoryID,
ReadSize,
Paddress,
0);
FileCount:=DWORD(MemoryID) + $104;
Pos:=DWORD(MemoryID) + $108;
FileSize:=FileSize - Pos;
ReAllocMem(MemoryID, FileSize);
Paddress:=SetFilePointer(FileHandle, Pos, 0, 0);
ReadFile(FileHandle, MemoryID, FileSize, Paddress, 0);
CloseHandle(FileHandle);
end;
end;
按照上面的代碼會出現記憶體讀取錯誤。。。求教各位前輩。。
uj5u.com熱心網友回復:
不懂擼過
uj5u.com熱心網友回復:
注意 指標 和 var引數型別 的使用uj5u.com熱心網友回復:
有前輩知道嗎 百度PureBasic的資料太少了。。uj5u.com熱心網友回復:
自己單步跟蹤了,遇到報錯,就修改var的引數 加、刪 @ 或 ^轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/130912.html
