I am writing an MFC based dialog application (COM server) that contains a COM object (class CAutomateDlgAutoProxy : public CCmdTarget
) for OLE automation. I have implemented an interface IAutomate
which is working absolutely fine when called from another process. So far so good.
Now I want to support the outgoing interface IAutomateEvents
. I have added INTERFACE_PART(CAutomateDlgAutoProxy, IID_IConnectionPointContainer, Automate)
in the interface map along with INTERFACE_PART(CAutomateDlgAutoProxy, IID_IAutomate, Automate)
and created a connection point also something like:
Server:
.h file:
BEGIN_CONNECTION_PART(CAutomateDlgAutoProxy, AutomateEvents)
CONNECTION_IID(IID_IAutomateEvents)
END_CONNECTION_PART(AutomateEvents)
.cpp file:
BEGIN_CONNECTION_MAP(CAutomateDlgAutoProxy, CCmdTarget)
CONNECTION_PART(CAutomateDlgAutoProxy, IID_IAutomateEvents, AutomateEvents)
END_CONNECTION_MAP()
The client is able to create the COM object and also QueryInterface
for IConnectionPointContainer
successfully.
Now here is the problem: when the client calls the following function the COM server returns the error DISP_E_BADINDEX
:
Client:
// cpc is a valid connection point container pointer.
IConnectionPointPtr cp;
hr = cpc->FindConnectionPoint(__uuidof(IAutomateEvents), &cp);
The following code in the MFC file oledisp1.cpp
is returning the error because itinfo
is not 0
:
STDMETHODIMP COleDispatchImpl::GetTypeInfo(UINT itinfo, LCID lcid,
ITypeInfo** pptinfo)
{
METHOD_PROLOGUE_EX_(CCmdTarget, Dispatch)
ASSERT_POINTER(pptinfo, LPTYPEINFO);
if (itinfo != 0) // itinfo is not 0
return DISP_E_BADINDEX;
IID iid;
if (!pThis->GetDispatchIID(&iid))
return DISP_E_BADINDEX;
return pThis->GetTypeInfoOfGuid(lcid, iid, pptinfo);
}
What is itinfo
? Why it is not 0
? I searched a lot but can’t find the details on IDispatch::GetTypeInfo()
and specifically the itinfo
parameter.
Thank you all!