[。NET中从WPF项目调用我的Delphi COM对象时未注册的类

问题描述 投票:1回答:1

[当我尝试从Visual Studio 2019(var x = new DelphiCOMServiceImplementation();)中的32位WPF .NET项目调用我的Delphi COM对象时,出现以下错误:

使用CLSID检索组件的COM类工厂由于以下原因,{D448873F-EAF7-4F40-8BC7-EF9853E64A0F}失败错误:80040154未注册类(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG))。>

在32位Delphi ActiveX项目侧(我正在运行Delphi 10.3),我的COM接口看起来像这样:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

TLB的Pascal接口生成如下:

interface

uses Winapi.Windows, System.Classes, System.Variants, System.Win.StdVCL, Vcl.Graphics, Vcl.OleServer, Winapi.ActiveX;


// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
//   Type Libraries     : LIBID_xxxx
//   CoClasses          : CLASS_xxxx
//   DISPInterfaces     : DIID_xxxx
//   Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  DelphiCOMServiceMajorVersion = 1;
  DelphiCOMServiceMinorVersion = 0;

  LIBID_DelphiCOMService: TGUID = '{E999851C-1E08-4C64-B82A-C3A979F96C2F}';

  IID_IDelphiCOMService: TGUID = '{D91553DB-A372-4279-AD31-9A1AE0C68F23}';
  CLASS_DelphiCOMServiceImplementation: TGUID = '{D448873F-EAF7-4F40-8BC7-EF9853E64A0F}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
  IDelphiCOMService = interface;
  IDelphiCOMServiceDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
  DelphiCOMServiceImplementation = IDelphiCOMService;


// *********************************************************************//
// Interface: IDelphiCOMService
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {D91553DB-A372-4279-AD31-9A1AE0C68F23}
// *********************************************************************//
  IDelphiCOMService = interface(IDispatch)
    ['{D91553DB-A372-4279-AD31-9A1AE0C68F23}']
    procedure EmbedWPFWindow(Pointer: LongWord; Width: SYSINT; Height: SYSINT); safecall;
    procedure WindowResized(Width: SYSINT; Height: SYSINT); safecall;
  end;

// *********************************************************************//
// DispIntf:  IDelphiCOMServiceDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {D91553DB-A372-4279-AD31-9A1AE0C68F23}
// *********************************************************************//
  IDelphiCOMServiceDisp = dispinterface
    ['{D91553DB-A372-4279-AD31-9A1AE0C68F23}']
    procedure EmbedWPFWindow(Pointer: LongWord; Width: SYSINT; Height: SYSINT); dispid 201;
    procedure WindowResized(Width: SYSINT; Height: SYSINT); dispid 202;
  end;

// *********************************************************************//
// The Class CoDelphiCOMServiceImplementation provides a Create and CreateRemote method to
// create instances of the default interface IDelphiCOMService exposed by
// the CoClass DelphiCOMServiceImplementation. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
  CoDelphiCOMServiceImplementation = class
    class function Create: IDelphiCOMService;
    class function CreateRemote(const MachineName: string): IDelphiCOMService;
  end;

implementation

uses System.Win.ComObj;

class function CoDelphiCOMServiceImplementation.Create: IDelphiCOMService;
begin
  Result := CreateComObject(CLASS_DelphiCOMServiceImplementation) as IDelphiCOMService;
end;

class function CoDelphiCOMServiceImplementation.CreateRemote(const MachineName: string): IDelphiCOMService;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_DelphiCOMServiceImplementation) as IDelphiCOMService;
end;

end.

我的Delphi CoClass实现如下(这是它似乎找不到已注册的类,所以我想知道我的实现是否正确或是否错过了一些细节):

unit DelphiCOMServiceUnit;

interface

uses ComObj, DelphiCOMService_TLB, Winapi.ActiveX, StdVcl;

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

implementation

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

end;

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

end;

end.

我已经尝试了regsvr32的32位和64位版本,没有任何问题(它总是成功注册):

regsvr32 DelphiCOMService.dll

C:\Windows\SysWOW64\regsvr32.exe DelphiCOMService.dll

我已经尝试在DelphiCOMService.dll上运行dumpbin / exports

,对我来说还好:

文件DelphiCOMService.dll的转储

文件类型:DLL

该部分包含DelphiCOMService.dll的以下导出

00000000 characteristics
       0 time date stamp
    0.00 version
       1 ordinal base
       8 number of functions
       8 number of names

ordinal hint RVA      name

      7    0 00101BE0 DllCanUnloadNow
      8    1 00101B98 DllGetClassObject
      4    2 00101C90 DllInstall
      6    3 00101C08 DllRegisterServer
      5    4 00101C4C DllUnregisterServer
      3    5 00065514 TMethodImplementationIntercept
      2    6 00010890 __dbk_fcall_wrapper
      1    7 00214640 dbkFCallWrapperAddr

摘要

    7000 .bss
    6000 .data
  997000 .debug
    1000 .didata
    1000 .edata
    4000 .idata
    2000 .itext
    1000 .rdata
   30000 .reloc
    7000 .rsrc
  208000 .text

谁能告诉我我该怎么做才能使C#能够调用我的Delphi COM对象的函数?我在创建包含DelphiCOMServiceImplementation类型的单元时是否错过了某些东西,或者在实现它时错过了一个细节,因此导致CoClass找不到作为注册对象?我试图找到我在Delphi版本中一直阅读的COM向导,以便使用它们创建一个类,并将有效的与无效的进行比较,但是我在我的Delphi版本中找不到用于创建的向导COM类。

[当我尝试从Visual Studio 2019中的32位WPF .NET项目调用我的Delphi COM对象时出现以下错误(var x = new DelphiCOMServiceImplementation();):检索COM类...

c# .net wpf delphi pascal
1个回答
1
投票

this guide之后,在MartynA的帮助下,我遇到了一些问题:

[首先,没有什么可以注册我的DelphiCOMServiceImplementation类,即使它具有正确的名称并且实现了正确的接口,该类也需要告诉COM它存在。为此,您添加一个初始化部分:

© www.soinside.com 2019 - 2024. All rights reserved.