今天手写了一个COM,并注册,注册没有设定ThreadingModel,当线程为CoInitializeEx(COINIT_APARTMENTTHREADED)时,一切正常,
当CoInitializeEx(COINIT_MULTITHREADED)时报不支持该接口,调试跟踪发现,有一个IID_IMarshal调用了COM结像的QueryInterface
导至报不支持此接口.
STDMETHODIMP CurrentThread::QueryInterface(REFIID riid, void **ppv)
{// 这里这是实现dynamic_cast的功能,但由于dynamic_cast与编译器相关。
if(riid == IID_ITestInterface)
*ppv = static_cast <ITestInterface*>(this);
else if(riid == IID_IUnknown)
*ppv = static_cast <ITestInterface*>(this);
else {
*ppv = 0;
return E_NOINTERFACE;
}
reinterpret_cast <IUnknown *>(*ppv)->AddRef(); //这里要这样是因为引用计数是针对组件的
return S_OK;
}
请问问题出在哪?