gpt4 book ai didi

c - 如何通过CreateInstanceLic获得许可的COM对象?

转载 作者:行者123 更新时间:2023-11-30 16:42:37 26 4
gpt4 key购买 nike

我正在尝试访问许可服务器的 com,因此我使用 IClassFactory2 来执行此操作所以。这是到目前为止我的代码:

// ...
IClassFactory2 class_factory;
hr = CoGetClassObject(
&clsid,
CLSCTX_LOCAL_SERVER,
NULL,
&IID_IClassFactory2,
(LPVOID*) &class_factory
);
if (hr != S_OK) { return 1; }
// ...
hr = class_factory.lpVtbl->CreateInstanceLic(
&class_factory,
NULL,
NULL,
&IID_IDispatch,
key,
(LPVOID)&dispatch
);
// ...

但是,对 CreateInstanceLic 的调用出现段错误。

Exception thrown at 0x00000001 in consoleapplication1.exe: 0xC0000005: Access violation reading location 0x00000001.

我认为原因是 class_factory.lpVtbl 看起来像这样:

    QueryInterface  oleaut32.dll!0x75769edc (Type information missing from symbol file) HRESULT(__stdcall*)(IClassFactory2 *, const _GUID * const, void * *)
AddRef 0x00000001 unsigned long(__stdcall*)(IClassFactory2 *)
Release 0x00401074 unsigned long(__stdcall*)(IClassFactory2 *)
CreateInstance 0x003f67a0 HRESULT(__stdcall*)(IClassFactory2 *, IUnknown *, const _GUID * const, void * *)
LockServer 0x003e777c HRESULT(__stdcall*)(IClassFactory2 *, int)
GetLicInfo 0x003e7778 HRESULT(__stdcall*)(IClassFactory2 *, tagLICINFO *)
RequestLicKey 0x757e60c4 {oleaut32.dll!_gPFactory} HRESULT(__stdcall*)(IClassFactory2 *, unsigned long, wchar_t * *)
CreateInstanceLic 0x00000001 HRESULT(__stdcall*)(IClassFactory2 *, IUnknown *, IUnknown *, const _GUID * const, wchar_t *, void * *)

我有点感觉 0x00000001 不是 CreateInstanceLic 应该位于的有效地址。所以我可能做错了什么,但不知道是什么。

最佳答案

所以应该是:

IClassFactory2 * class_factory;
hr = CoGetClassObject(
&clsid,
CLSCTX_LOCAL_SERVER,
NULL,
&IID_IClassFactory2,
&class_factory
);
if (hr != S_OK) { return 1; }
// ...
IDispatch * dispatch;
hr = class_factory.lpVtbl->CreateInstanceLic(
&class_factory,
NULL,
NULL,
&IID_IDispatch,
key,
&dispatch
);

关于c - 如何通过CreateInstanceLic获得许可的COM对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45759957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com