我有一段代碼使用Delphi XE3編譯爲64位COM DLL。CopyMemory導致Win8上的訪問衝突
function TRPMFileReadStream.Read(var Buffer; const Count: Longint): Longint;
begin
if ((Self.FPosition >= 0) and (Count > 0)) then
begin
Result := Self.FSize - Self.FPosition;
if ((Result > 0) and (Result >= Count)) then
begin
if (Result > Count) then
begin
Result := Count;
end;
CopyMemory(
Pointer(@Buffer),
Pointer(LongWord(Self.FMemory) + Self.FPosition),
Result
);
Inc(Self.FPosition, Result);
Exit;
end;
end;
Result := 0;
end;
在Win7-64bit上,以上工作正常。 但在Win8-64bit上,同一個DLL文件會在CopyMemory上拋出訪問衝突。 CopyMemory是在WinAPI.windows單元中實現的。
就是這樣。
procedure CopyMemory(Destination: Pointer; Source: Pointer; Length: NativeUInt);
begin
Move(Source^, Destination^, Length);
end;
任何想法?謝謝。
爲什麼u使用CopyMemory的,而不是標準的Pascal'Move'程序?或者,如果你不喜歡標準函數,那麼來自http://FastCode.sf.net的優化函數呢? – 2013-04-10 15:55:53
@ Arioch'The 32位編譯器使用FastCode'Move',沒有64位FastCode'Move'。 – 2013-04-10 15:58:02
我不能說Doctorlai,@Arioch,但*我更喜歡'CopyMemory',因爲我發現指針比無類型的引用參數更容易挖掘,並且我每天都以多種語言工作,所以擁有一個通用API是有幫助的。此外,由於API將所有內容直接轉發給內置函數,所以任何人都可以選擇。 – 2013-04-10 16:01:14