I have a COM class CMyCOMServer
implementing IMyInterface
in one application, both with correct GUIDs. CMyCOMServer::QueryInterface
will return S_OK (and cast itself to the right type) if IUnknown or IMyInterface is requested, otherwise it returns E_NOINTERFACE.
In another app on the same PC, I call:
HRESULT hr = ::CoCreateInstance(__uuidof(CMyCOMServer), 0, CLSCTX_SERVER,
__uuidof(IMyInterface ),(void **)&pInterface);
It returns E_NOINTERFACE. So I assumed I was doing something wrong and added a breakpoint on CMyCOMServer::QueryInterface
. I found that when CoCreateInstance
is called, QueryInterface
is triggered several times for different interfaces:
- First, IUnknown is requested - no problem
- Then, several interfaces like IMarshall etc are requested... these are not supported so E_NOINTERFACE is returned
- Finally, IMyInterface is requested. I verify QueryInterface returns S_OK and sets
(IMyInterface *)this
as the interface pointer, as expected
So my confusion is why the calling CoCreateInstance is leaving me a NULL pointer and return code of E_NOINTERFACE, when the COM server app is clearly returning the interface I ask for?
EDIT: my client app calls CoInitialize(NULL) at startup, this makes no difference.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…