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

时间:2017-08-18 15:14:58

标签: c com

我试图访问许可服务器的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所在的有效地址。所以我可能做错了什么但不知道是什么。

1 个答案:

答案 0 :(得分:0)

所以它应该是:

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
);