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 1052423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:05:29+00:00 2026-05-16T17:05:29+00:00

I’m trying to create a Gecko 2.0-compatible DLL in Delphi. Previously (pre-Gecko 2.0) the

  • 0

I’m trying to create a Gecko 2.0-compatible DLL in Delphi.

Previously (pre-Gecko 2.0) the DLL needed to export a NSGetModule() function. This worked flawlessly.

Starting with Firefox 4, my DLL is getting loaded (I have verified this though a breakpoint in my initialization section), but my NSGetModule() function does not get called anymore. This is the designed behavior because starting with Gecko 2.0 (Firefox 4), a binary component is not supposed to export a NSGetModule() function:

https://developer.mozilla.org/en/XPCOM/XPCOM_changes_in_Gecko_2.0#Binary_components

According to these docs, my DLL needs to export a NSModule data symbol which points to a struct. In Delphi terminology, I assume this is a global variable which points to a Delphi record.

In C++, this is how you export the (global) data symbol:

define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule

My question: how do I accomplish this in Delphi? How do I export a global variable?

I appreciate your feedback.

  • 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-16T17:05:29+00:00Added an answer on May 16, 2026 at 5:05 pm

    Delphi exports global variables from DLLs in a similar way to how it exports functions:

    library exp;
    var
      global: Integer;
    exports global;
    end.
    

    Delphi can import global variables from DLLs, but it’s a bit of a hack: declare a DLL import procedure of the same name as the global to import, then get the address of the procedure and adjust it appropriately. DLL imported procedures, from Delphi’s perspective, are stubs that do an indirect jump through the DLL import table. Exported variables are linked by the OS loader by putting the address of the exported global in the import table, almost exactly like how addresses of exported procedures are similarly patched in.

    For example:

    {$apptype console}
    
    procedure global; external 'exp.dll';
    
    function GetGlobalAddr: PInteger;
    type
      PPPointer = ^PPointer;
    var
      p: PByte;
    begin
      p := @global;
      Assert(p^ = $FF); // $FF $25 => indirect jump m32
      Inc(p);
      Assert(p^ = $25);
      Inc(p);
      Result := PPPointer(p)^^
    end;
    
    begin
      Writeln(GetGlobalAddr^);
    end.
    

    Of course, the latter details are implementation and platform dependent etc. Probably a safer approach is to use LoadLibrary with GetProcAddress, which will return the address of the global variable when passed its name. Of course, that’s also platform dependent.

    64-bit update:

    In 64-bit on Windows, the code is slightly different. The opcodes are the same, but the addressing mode for the same instruction sequence is different; instead of a 32-bit absolute offset, it’s a 32-bit relative offset.

    function GetGlobalAddr: PInteger;
    type
      PPPointer = ^PPointer;
    var
      p: PByte;
      ofs: Integer;
    begin
      p := @global;
      Assert(p^ = $FF); // $FF $25 => indirect jump m32
      Inc(p);
      Assert(p^ = $25);
      Inc(p);
      // 32-bit offset follows
      ofs := PInteger(p)^;
      // offset is relative to next instruction
      Inc(p, SizeOf(ofs) + ofs);
      Result := PPPointer(p)^^
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.