delphi - 如何在Delphi 7中获取GIT?

标签 delphi com marshalling

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

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,才能在注册表中获取此定义? 还是我做的完全错误?

最佳答案

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

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.

关于delphi - 如何在Delphi 7中获取GIT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1070571/

相关文章:

c# - 使用 MemoryMappedViewAccessor 错误编写打包结构?

delphi - 如何保留多个 Delphi 版本的编译代码?

ios - 如何访问 iOS 中的指南针?

c++ - 帮助解决一个非常奇怪的 COM+ 调用堆栈

c# - 从 c# .net 代码返回 S_OK 或 E_FAIL 的值是什么?

xml - 通过 UnMarshal 和 MarshalIndent 往返 xml

c++ - 从另一个进程访问 STA 对象时出现问题

delphi - 用什么替换在nextgen下不推荐使用的TSysCharSet?

德尔福悸动者

c++ - QAxObject 没有为 COM 对象创建槽信号