我尝试使用以下代码(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/