Delphi COM object not showing up in .NET

4

I am trying to create a COM object in Delphi and use it in a C# WPF project.

I have created a new DLL project in Delphi 10.3, using File -> New -> Other, then Delphi -> Windows -> ActiveX Library. I have created the following IDL in the GUI editor for my *.ridl file:

[
  uuid(E999851C-1E08-4C64-B82A-C3A979F96C2F),
  version(1.0)

]
library DelphiCOMService
{

  importlib("stdole2.tlb");

  interface IDelphiCOMService;


  [
    uuid(50749CD6-4BA7-4200-AB87-67D9590EAA1A),
    version(1.0),
    dual,
    oleautomation
  ]
  interface IDelphiCOMService: IDispatch
  {
    [id(0x000000C9)]
    HRESULT _stdcall EmbedWPFWindow([in] unsigned long Pointer, [in] int Width, [in] int Height);
    [id(0x000000CA)]
    HRESULT _stdcall WindowResized([in] int Width, [in] int Height);
  };

};

In Design view, I hit Refresh Implementation, Register Type Library, and Save As Type Library File. It says registration of the ActiveX Server was successful. I hit Build on my project. No errors or issues.

I added the following unit to implement the interface:

unit DelphiCOMServiceImplementation;

interface

uses ComObj, DelphiCOMService_TLB, Winapi.ActiveX;

type
  DelphiCOMService = class(TAutoObject, IDelphiCOMService)
  public
    procedure EmbedWPFWindow(Pointer: LongWord; Width: SYSINT; Height: SYSINT); safecall;
    procedure WindowResized(Width: SYSINT; Height: SYSINT); safecall;
  end;

implementation

procedure DelphiCOMService.EmbedWPFWindow(Pointer: LongWord; Width: SYSINT; Height: SYSINT); safecall;
begin

end;

procedure DelphiCOMService.WindowResized(Width: SYSINT; Height: SYSINT); safecall;
begin

end;

end.

I rebuilt my project, no errors so far. I went and hit Run -> ActiveX Server -> Register. It was successful.

I would expect it to have a registered the COM object on my system now, or am I wrong? In my WPF C# project, when I try to Add Reference..., it does not show up under COM -> Type Libraries. Am I missing something?

c#
.net
wpf
delphi
pascal
asked on Stack Overflow Nov 9, 2019 by Alexandru

1 Answer

0

I rebuilt the COM object's interface in the *.ridl Design editor; I tried adding the same interface as a DispInterface just for kicks, that didn't work, and then, deleting the DispInterface and adding back the original Interface seemed to work (+ Refresh, Register, and Save as TLB). Also, I noticed that leaving a Version of 0.0 for my interface may be the reason why it worked. Originally, I tweaked the Version to 1.0 when I first built it out. If someone could shed some light as to why this could happen, I would also be quite intrigued to know!

answered on Stack Overflow Nov 12, 2019 by Alexandru

User contributions licensed under CC BY-SA 3.0