我有一段代码使用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