Delphi的COM对象无法在.NET中显示

4

我正在尝试在Delphi中创建一个COM对象,并在C# WPF项目中使用它。

我在Delphi 10.3中创建了一个新的DLL项目,使用文件-> 新建 -> 其他,然后选择Delphi -> Windows -> ActiveX库。我在我的*.ridl文件的GUI编辑器中为以下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);
  };

};

在设计视图中,我点击了“刷新实现”,“注册类型库”和“另存为类型库文件”。它显示ActiveX服务器的注册成功。我在项目上点击了“生成”按钮。没有错误或问题。
我添加了以下单元来实现该接口:
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.

我重建了我的项目,目前还没有错误。我点击了运行 -> ActiveX 服务器 -> 注册。操作成功。

我期望它已经在我的系统上注册了COM对象,或者我错了吗?在我的WPF C#项目中,当我尝试添加引用…时,在COM ->类型库下它没有显示。我有什么遗漏吗?


Delphi是本地的,因此可能存在32位与64位问题。尝试将Delphi库编译为64位? - Marco van de Voort
@MarcovandeVoort Delphi和WPF解决方案都是32位的,因此应该在两侧都编译为32位。 - Alexandru
如果您使用IDE的主菜单并选择组件->导入组件->导入ActiveX控件,您的ActiveX是否显示在导入列表中? - Ken White
@KenWhite 不,它没有。奇怪... - Alexandru
如果您尝试使用Delphi的TRegSvr实用程序注册您的dll,您会得到什么结果和消息? - MartynA
显示剩余4条评论
1个回答

0

我在 *.ridl 设计编辑器中重建了 COM 对象的接口;出于好奇,我尝试添加了相同的接口作为 DispInterface,但没有成功,然后删除了 DispInterface,并重新添加原始接口似乎可以解决问题(+ 刷新、注册和另存为 TLB)。此外,我注意到将我的接口版本留为 0.0 可能是它工作的原因。最初,我在第一次构建时将版本调整为 1.0。如果有人能够说明这可能发生的原因,我也会很感兴趣!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接