我正在尝试在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 ->类型库下它没有显示。我有什么遗漏吗?