Hydra plugin message to host


(marcantheunis) #1

How does a non-visual .NET plugin send a message (event) to the (delphi) host?

My non-visual plugin does not have a form that can implement a hydra interface for the feedback
How does the host receive those events?

The only property I notice in the hydra module manager is OnPluginMessage: THYPluginMessageEvent
but this is deprecated


(antonk) #2

Hello

Let’s rephrase your question to ‘Can my plugin call a method on the host?’.

Sure. Such calls are the main purpose of Hydra.

Here is a sample, that will show you interop calls in action: HostEventTriggering.zip

This sample contains a Delphi host and .NET plugin.

To run this sample build both host and plugin projects. Then run the NewHostApplication.exe. Press the Load Plugin button to load .NET plugin. Then press the Send Event button to call a host Delphi method from .NET plugin.

Let’s take a closer look at the host app code:

The uCustomInterfaces.pas file contains 2 interop interfaces.

The fMain.pas file contains code

  HYModuleManager1.LoadModule('ManagedModule.dll');
  HYModuleManager1.CreateVisualPlugin('ManagedModule.Plugin1', fPlugin, Panel1);
  (fPlugin as IInterfaceThatHasEvents).SetEventSink(Self);

Here a plugin is loaded from dll. Then this plugin is instantiated and then a method of this plugin is called.

In the plugin code we can see

private ImyInterfaceEvents fEventSink;

public void SetEventSink(ImyInterfaceEvents Sink)
{
    fEventSink = Sink;
}

private void button1_Click(object sender, EventArgs e)
{
    if (fEventSink != null)
        fEventSink.ButtonClick(this);
}

As you can see the 1st method is called from the host size. The 2nd method in this code snippet in its turn calls a method in callback interface provided earlier by the host. Essentially it calls a method in the host.

Note that implementation is not tied to a plugin or host having a form. In this sample VisualPlugin is used only to provide a simple way to start a Plugin-> Host method call operation. This approach can as well be used for non-visual plugins.

Regards


(marcantheunis) #3

This works, thanks