Jump to content
jaenicke

AppCentral - Communication with interfaces in / between host application / DLLs / C#

Recommended Posts

I first used interfaces via exported DLL functions. This was better than using many individual DLL functions, but still not very flexible.

 

So I thought about how to implement the whole thing in a more general way. The result is this project.

 

With AppCentral you can register interfaces in the host application or a DLL and get them in the host application or another DLL. The DLL can thereby also be written in C#, which is very practical, because you can connect various .NET libraries very well with Delphi.

 

Example:
Register an interface in Delphi


type
  IAppDialogs = interface
  ['{EA3B37D8-5603-42A9-AC5D-5AC9C70E165C}']
    procedure ShowMessage(const AMessage: WideString); safecall;
  end;

  TAppDialogs = class(TInterfacedObject, IAppDialogs)
   public
     procedure ShowMessage(const AMessage: WideString); safecall;
   end;

implementation

{ TAppDialogs }

procedure TAppDialogs.ShowMessage(const AMessage: WideString);
begin
  Vcl.Dialogs.ShowMessage(AMessage);
end;

initialization
  TAppCentral.Reg<IAppDialogs>(TAppDialogs.Create);

finalization
  TAppCentral.Unreg<IAppDialogs>;

Fetch the interface in the host application or a DLL

  TAppCentral.Get<IAppDialogs>.ShowMessage('This is a message!');
  // fetch directly, an exception will occur, if the interface is not registered yet

Or in C#

if (AppCentral.TryGet<IAppDialogs>(out IAppDialogs Dialogs))
{
  Dialogs.ShowMessage("Message from DLL: C# DLL registered!");
} 

The project can be downloaded here:
https://github.com/jaenicke/appcentral

Demo applications are included in source and in compiled form.

 

I'll add a quick start manual soon.

Edited by jaenicke
  • Like 5

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×