multiple IDispatches
-
I'm writing a com component that has two interfaces that derive from IDispatch. When I compiled the project I got the error: error C2594: 'static_cast' : ambiguous conversions from 'class CExplorerBar *' to 'struct IDispatch *'. So I changed the COM_INTERFACE_ENTRY to COM_INTERFACE_ENTRY2, so I could specify the IDispatch. Now I have 1 error and 3 warning (I'll just post the error): c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : error C2259: 'CComObject' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator >::CreateInstance(void *,const struct _GUID &,void ** )'. Any ideas about what's going on? Thanks. Melinda.
-
I'm writing a com component that has two interfaces that derive from IDispatch. When I compiled the project I got the error: error C2594: 'static_cast' : ambiguous conversions from 'class CExplorerBar *' to 'struct IDispatch *'. So I changed the COM_INTERFACE_ENTRY to COM_INTERFACE_ENTRY2, so I could specify the IDispatch. Now I have 1 error and 3 warning (I'll just post the error): c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : error C2259: 'CComObject' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator >::CreateInstance(void *,const struct _GUID &,void ** )'. Any ideas about what's going on? Thanks. Melinda.
You cannot inherit from two interfaces derived from IDispatch, because the IDispatch is not a virtual base class ( as the error message is saying, the compiler cannot decide which base class to consider for casting).You can disambiguate the cast by specifying which base class to consider ( (IDispatch*)(IInterface1*)this). Another issue is that you will have DISPID clashes from the two interfaces ( id 1 assigned to method "test" in iface 1, and for method "clone" for iface2). The solution is dispid encoding ( you can find an article on codeguru about this), manually implementing IDispatch or using tear-off objects.