4

我正在尝试使用以下代码(Delphi)获取全局接口表:

uses Comobj, ActiveX;

var
   cGIT : IGlobalInterfaceTable = NIL;
const
   CLSID_StdGlobalInterfaceTable: TGUID = '{00000146-0000-0000-C000-000000000046}';


function GIT : IGlobalInterfaceTable;
begin
   if (cGIT = NIL) then
      OleCheck (CoCreateInstance (CLSID_StdGlobalInterfaceTable, NIL,
                                  CLSCTX_ALL, IGlobalInterfaceTable, cGIT ));
  Result := cGIT;
end;

但是,CoCreateInstance 会引发“类未注册”异常。事实上:在 HKCR/CLSID 中没有 {00000146- 等 } 的条目。

应该注册哪个 dll 或 ocx,才能在注册表中获取此定义?还是我做错了?

4

3 回答 3

7

这是我的单位。我在 D2006 中编译时将其放在一起,但我不明白为什么在 D7 中会有所不同。我使用它来存储 DCOM 服务器的接口并在多个线程之间共享它。

unit GlobalInterfaceTable;

interface

uses Types,
     ActiveX;

type
  IGlobalInterfaceTable = interface(IUnknown)  
     ['{00000146-0000-0000-C000-000000000046}']  
     function RegisterInterfaceInGlobal (pUnk : IUnknown; const riid: TIID; out dwCookie : DWORD): HResult; stdcall;  
     function RevokeInterfaceFromGlobal (dwCookie: DWORD): HResult; stdcall;  
     function GetInterfaceFromGlobal (dwCookie: DWORD; const riid: TIID; out ppv): HResult; stdcall;  
   end;

  function GIT: IGlobalInterfaceTable;

implementation

uses ComObj;

const
  CLSID_StdGlobalInterfaceTable : TGUID = '{00000323-0000-0000-C000-000000000046}';

function GIT: IGlobalInterfaceTable;  
begin  
  // This function call always returns the singleton instance of the GIT  
  OleCheck(CoCreateInstance (CLSID_StdGlobalInterfaceTable, NIL, CLSCTX_ALL, IGlobalInterfaceTable, Result));  
end;

end.
于 2009-07-01T21:04:09.347 回答
5

您错误地定义了 CLSID_StdGlobalInterfaceTable:您提供了接口的 GUID 而不是具体的类。

我没有 Windows 头文件,所以我无法检查它们,但搜索表明它应该是:

 CLSID_StdGlobalInterfaceTable: TGUID = '{00000323-0000-0000-C000-000000000046}';
于 2009-07-01T18:32:31.143 回答
2

您是否使用过 OleView32 来验证类的 GUID?该实用程序在 Windows SDK 中可用,它允许您比 regedit 更轻松地浏览接口注册表。我会将该实用程序归类为任何 COM 开发的必备工具。

于 2009-07-01T18:35:33.383 回答