WinForms Host, Delphi NonVisualPlugin, and cross platform bi-directional interfaces

I am trying to implement bi-directional interfaces between a WinForms host and a Delphi non-visual plugin. Attached are my sample projects. I can create the non-visual plugin and use its methods. What I cannot do is get the non-visual plugin to use the interface methods in the host (e.g., callbacks). Can you please take a look and let me know what I’m doing wrong?

TestPluginLibrary.zip (5.9 KB)
TestPluginHost.zip (823.8 KB)

Hello

It seems that you run into some kind of limitations of .NET implementation of COM (it is not very good with COM interfaces inheritance).

I suggest you define a separate interface for your callback methods and then set it explicitly. F.e. in your sample it would look like

  // Original Name: TestPlugin.ITestInterface
  ITestInterface = interface(IHYCrossPlatformInterface)
  ['{0f9d9dbc-bb10-4c03-930c-e5987ef39aa7}']
    function ConsumeMessage(const Msg: WideString): WideString; safecall;
    procedure SetCallbackSite(const site: ICallbackSite); safecall;
  end;

  // Original Name: TestPlugin.ICallbackSite
  ICallbackSite = interface(IHYCrossPlatformInterface)
  ['{d8ae3524-7237-4abe-aa9b-18a3fca2b16c}']
    function ConsumeMessageCallback(const Msg: WideString): WideString; safecall;
  end;

Regards

Thanks, that works.

Oh, and a small thing, but when you import .pas interfaces in Visual Studio 2017 (other versions?), it doesn’t separate the file extension in the .cs filename. Screenshot is attached.

34%20AM

Thanks, logged as bugs://79818

Thanks for the report

bugs://79818 got closed with status fixed.