English 中文(简体)
Delphi XE2: Invoke WinAPI Enum Resource 姓名造成Win64平台的出入被侵犯
原标题:Delphi XE2: Invoke WinAPI EnumResourceNames cause access violation in Win64 platform

在Delphi XE2 Win32平台运行以下代码。 然而,如果以“EnumRCDataProc”的形式运行,在“EnumRCDataProc”平台上汇编的同一法典将造成出入违规:

procedure TForm2.Button1Click(Sender: TObject);
  function EnumRCDataProc(hModule: THandle; lpszType, lpszName: PChar; lParam:
      NativeInt): Boolean; stdcall;
  begin
    TStrings(lParam).Add(lpszName);
    Result := True;
  end;

var k: NativeInt;
    L: TStringList;
    H: THandle;
begin
  H := LoadPackage( resource.bpl );
  L := TStringList.Create;
  try
    EnumResourceNames(H, RT_RCDATA, @EnumRCDataProc, NativeInt(L));
    ShowMessage(L.Text);
  finally
    L.Free;
    UnloadPackage(H);
  end;
end;

在对Delphi XE2 IDE在Win64平台上的代码进行脱节时,我发现EnumRCDataProc中的ule价值与H变量相吻合。 然而,我怎么说。 任何想法?

最佳回答

问题是,你已制定地方程序。 你们需要将其移出方法之外。

function EnumRCDataProc(hModule: HMODULE; lpszType, lpszName: PChar; lParam:
    NativeInt): BOOL; stdcall;
begin
  TStrings(lParam).Add(lpszName);
  Result := True;
end;

procedure TForm2.Button1Click(Sender: TObject);
var k: NativeInt;
    L: TStringList;
    H: HMODULE;
begin
  H := LoadPackage( resource.bpl );
  L := TStringList.Create;
  try
    EnumResourceNames(H, RT_RCDATA, @EnumRCDataProc, NativeInt(L));
    ShowMessage(L.Text);
  finally
    L.Free;
    UnloadPackage(H);
  end;
end;

第一次检查 我预计,汇编者会发现你的法典有一处错误:

E2094 当地程序/职能

但它没有这样做。 我更深了一点,发现<代码>的备用参数。 EnumResourceNames为Pointer。 如果标题译本宣布这一为一类的背负参数,那么上述错误信息的确会发出。 我认为,这方面的翻译工作做得很差。 放弃此类系统的安全似乎没有什么好处。

你们的法典在32条轨道法典中发挥作用,这只是一个取决于执行细节的好巧合。 页: 1 同样,如果能够建立此类检查制度,汇编者会立即告诉你错误。

其他评论:

  1. The EnumRCDataProc has a couple of incorrect types in its declaration: hModule should be of type HMODULE and the function result should be BOOL.
  2. LoadPackage is a rather heavyweight approach to getting a module handle. I would prefer to see LoadLibraryEx with the LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE and LOAD_LIBRARY_AS_IMAGE_RESOURCE options.
问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签