Roc*_*uck 4 delphi com marshalling
我正在尝试使用以下代码(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;
Run Code Online (Sandbox Code Playgroud)
但是,CoCreateInstance会抛出"未注册类"异常.事实上:在HKCR/CLSID中,{00000146-等没有条目.
应该注册哪个dll或ocx才能在注册表中获得此定义?或者我完全错了吗?
这是我的单位.当我在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.
Run Code Online (Sandbox Code Playgroud)
您已错误地定义了CLSID_StdGlobalInterfaceTable:您提供了接口的GUID而不是具体的类.
我没有Windows头文件,所以我不能检查它们,但搜索建议它应该是:
CLSID_StdGlobalInterfaceTable: TGUID = '{00000323-0000-0000-C000-000000000046}';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2665 次 |
| 最近记录: |