Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7049353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:00:12+00:00 2026-05-28T03:00:12+00:00

Running the following code in Delphi XE2 Win32 platform works. However, the same code

  • 0

Running the following code in Delphi XE2 Win32 platform works. However, the same code compile in win64 platform will cause access violation in “EnumRCDataProc” if run in debug mode:

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;

When debug the code in Delphi XE2 IDE on Win64 platform, I found the value of hModule in EnumRCDataProc doesn’t match with variable H. I suspect that might be something wrong about the parameters I constructed for the EnumRCDataProc. However, I can’t figure out how. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:00:13+00:00Added an answer on May 28, 2026 at 3:00 am

    The problem is that you have made EnumRCDataProc a local procedure. You need to move it outside the method.

    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;
    

    On first inspection I expected that the compiler would emit an error with your code:

    E2094 Local procedure/function ‘Callback’ assigned to procedure variable

    But it does not do so. I dug a little deeper and discovered that the callback parameter for EnumResourceNames is declared as type Pointer. If the header translation had declared this as a typed callback parameter then the above error message would indeed have been emitted. To my mind the header translation is poor in this regard. There seems very little to be gained from abandoning the safety of the type system.

    The fact that your code works in 32 bit code is just a happy coincidence that relies on implementation details. Your luck runs out on 64 bit. Again, if the type checking system had been enabled, the compiler could have told you what was wrong immediately.

    Some other comments:

    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.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running following PHP code to interact with a MS Access database. $odbc_con
When running the following code, which is an easy problem, the Python interpreter works
Running the following code, I get a StackOverflowError at the getPackage() line. How can
When running the following code it leaves out one row. When I do a
When running the following code I get no output but I cannot work out
I am currently running the following code based on Chapter 12.5 of the Python
I'm running the following code to get a random entry from a dictionary: SELECT
I'm running the following code to update the database according to the data I
I am running the following code in tableView:cellForRowAtIndexPath: File *file = [[File alloc] init];
I'm running the following code on a list of strings to return a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.