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

  • Home
  • SEARCH
  • 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 7668185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:17:48+00:00 2026-05-31T15:17:48+00:00

Can I call a method which is placed in main application from dll code?

  • 0

Can I call a method which is placed in main application from dll code?

  • 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-31T15:17:49+00:00Added an answer on May 31, 2026 at 3:17 pm

    seems there is only one way to do it – create a callback object.
    in your application you have to declare interface, wich describes your method, for example:

    IMyMethodInterface = interface(IInterface)
        procedure MyMethod(); stdcall;
    end;
    

    next you have to create class, wich implements this interface (and your method):

    TMyMethodObject = class(TInterfacedObject, IMyMethodInterface)
      public
        procedure MyMethod(); stdcall;
    end;
    

    when you load DLL, you have to create TMyMethodObject instance and pass its IMyMethodInterface to dll; of course dll has to have corresponding method and export it (wich takes interface as parameter) SetMethodCallback wich stores interface reference:

    vars:

    var mmo : IMyMethodInterface;
        dllHandle : THandle;
        smc : procedure (mmi : IMyMethodInterface); stdcall;
    

    code:

        mmo := TMyMethodObject.Create();
    
        dllHandle := LoadLibrary('mydll.dll');
        smc := GetProcAddress(dllHandle, 'SetMethodCallback');
        if assigned(smc) then
            smc(mmo);
    

    now, you can use IMyMethodInterface reference in your dll to call method.

    of course you can statically link dll and use it directly:

    procedure SetMethodInteface(mmi : IMyMethodInterface); stdcall; external 'mydll.dll';
    

    here is an DLL sample code:

    library Project3;
    // uses YourMethodIntf.pas
    {$R *.res}
    
    var AppMethod : IMyMethodInterface;
    
        procedure SetAppMethodCallback(mmi : IMyMethodInterface); stdcall;
        begin
            AppMethod := mmi;
        end;
    
        procedure AnotherDllMethod();
        begin
            //here you can use AppMethod.MyMethod();
        end;
    
    exports
        SetAppMethodCallback name 'SetMethodcallback';
    
    begin
    end.
    

    take into account that your mmo object (TMyMethodInterface) will not be destroyed until you set AppMethod in dll to nil (or FreeLibrary dll ), so be careful

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to create a generic method which can call overloaded methods? I tried but
Can I call public method from within private one: var myObject = function() {
Can one call a method from another model in a model in CodeIgniter? I
how can I call a method from another class and not be restriced to
In Ruby I think you can call a method that hasn't been defined and
Opah! Is there any way I can call a method in the controller through
How can I call a method asynchronously ?
How can I call a method in one of my controller classes without grails
Hi I was wondering how can I call a method just for one time
How can I call an onTouch method programmatically by dispatching a fake touch event?

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.