简体   繁体   English

Delphi COM object 未出现在 .NET

[英]Delphi COM object not showing up in .NET

I am trying to create a COM object in Delphi and use it in a C# WPF project. 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 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:我在 GUI 编辑器中为我的 *.ridl 文件创建了以下 IDL:

[
  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 .在设计视图中,我点击Refresh ImplementationRegister Type LibrarySave As Type Library File It says registration of the ActiveX Server was successful.它说 ActiveX 服务器注册成功。 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 .我去点击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?我希望它现在在我的系统上注册了 COM object,还是我错了? In my WPF C# project, when I try to Add Reference... , it does not show up under COM -> Type Libraries .在我的 WPF C# 项目中,当我尝试添加参考...时,它没有出现在COM -> 类型库下。 Am I missing something?我错过了什么吗?

I rebuilt the COM object's interface in the *.ridl Design editor;我在 *.ridl 设计编辑器中重建了 COM 对象的界面; 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).我尝试添加与 DispInterface 相同的接口只是为了踢球,但这不起作用,然后,删除 DispInterface 并重新添加原始接口似乎有效(+ 刷新、注册和另存为 TLB)。 Also, I noticed that leaving a Version of 0.0 for my interface may be the reason why it worked.另外,我注意到为我的界面保留 0.0 版本可能是它起作用的原因。 Originally, I tweaked the Version to 1.0 when I first built it out.最初,当我第一次构建它时,我将版本调整为 1.0。 If someone could shed some light as to why this could happen, I would also be quite intrigued to know!如果有人能解释为什么会发生这种情况,我也很想知道!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM