Multiple Inheritance by IDispatch
-
Hi everyone, I have a class that implements an interface that derives from IDispatch directly,and I want to add a new interface which also derives from IDispatch,and then derive my class from this interface too.Expectedly,my problem is ambiguouty (did I spell it correctly??).I use
COM_INTERFACE_ENTRY2
macro,but i keep getting error "cannot instantiate abstract class" error in atlcom.h this is the IDL file:library TheLibrary { importlib("stdole2.tlb"); [ object, uuid(), dual, nonextensible, helpstring("Primary dispatch interface for the class."), pointer_default(unique) ] interface ISomething : IDispatch { }; [ uuid(), helpstring("help string.") ] coclass CSomething { [default] interface ISomething}; [ uuid(), nonextensible, helpstring("the new Interface"), ] dispinterface INewInterface { properties: methods: [id(0), helpstring("method default"), local] HRESULT DefaultMethod(void); };
and this is the COM mapping
BEGIN_COM_MAP(CSomething) COM_INTERFACE_ENTRY(ISomething) COM_INTERFACE_ENTRY2(IDispatch, ISomething) COM_INTERFACE_ENTRY(IObjectWithSite) COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDeskBand) COM_INTERFACE_ENTRY(IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IInputObject,IInputObject) COM_INTERFACE_ENTRY(IPropertyNotifySink) COM_INTERFACE_ENTRY(INewInterface) END_COM_MAP()
I tried using
interface
instead ofdispinterface
.Didn't help either.I know I'm missing something,but can't figure out what it is... -
Hi everyone, I have a class that implements an interface that derives from IDispatch directly,and I want to add a new interface which also derives from IDispatch,and then derive my class from this interface too.Expectedly,my problem is ambiguouty (did I spell it correctly??).I use
COM_INTERFACE_ENTRY2
macro,but i keep getting error "cannot instantiate abstract class" error in atlcom.h this is the IDL file:library TheLibrary { importlib("stdole2.tlb"); [ object, uuid(), dual, nonextensible, helpstring("Primary dispatch interface for the class."), pointer_default(unique) ] interface ISomething : IDispatch { }; [ uuid(), helpstring("help string.") ] coclass CSomething { [default] interface ISomething}; [ uuid(), nonextensible, helpstring("the new Interface"), ] dispinterface INewInterface { properties: methods: [id(0), helpstring("method default"), local] HRESULT DefaultMethod(void); };
and this is the COM mapping
BEGIN_COM_MAP(CSomething) COM_INTERFACE_ENTRY(ISomething) COM_INTERFACE_ENTRY2(IDispatch, ISomething) COM_INTERFACE_ENTRY(IObjectWithSite) COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDeskBand) COM_INTERFACE_ENTRY(IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IInputObject,IInputObject) COM_INTERFACE_ENTRY(IPropertyNotifySink) COM_INTERFACE_ENTRY(INewInterface) END_COM_MAP()
I tried using
interface
instead ofdispinterface
.Didn't help either.I know I'm missing something,but can't figure out what it is...ajitatif angajetor wrote:
ambiguouty (did I spell it correctly??)
No - ambiguity - close, though :-) Anyway - I've had a look through my code collection - I have a class that implements two
IDispatch
interfaces, in ATL 3.0 (it's an old VC6 project). Here's the relevant bit of the IDL:[ uuid(01b836c6-51c8-4476-bf15-ae91b0fe74f6), oleautomation, dual ] interface ICommands : IDispatch { [id(1), helpstring("method RereadEnvironment")] HRESULT RereadEnvironment(); }; [ hidden, uuid(0309A24D-B3E7-4C6A-8ACD-B3F0F8FAA483) ] coclass ApplicationEvents { [default] dispinterface IDispApplicationEvents; } [ uuid(6c5658bc-946b-4bc7-94bf-5530cad3d654) ] coclass Commands { [default] interface ICommands; };
and code
class ATL_NO_VTABLE CCommands : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CCommands, &CLSID_Commands>, public IDispatchImpl<ICommands, &IID_ICommands, &LIBID_DSWENVLib>, public IDispatchImpl<IApplicationEvents, &IID_IApplicationEvents, &LIBID_DSWENVLib> { BEGIN_COM_MAP(CCommands) COM_INTERFACE_ENTRY(ICommands) COM_INTERFACE_ENTRY2(IDispatch, ICommands) COM_INTERFACE_ENTRY(IApplicationEvents) END_COM_MAP() DECLARE_NOT_AGGREGATABLE(CCommands) <class continues>
Don't know if there's anything obvious there - the COM map looks very similar to yours - what about the inheritance? Do you have an
IDispatchImpl
inheritance for eachIDispatch
interface you want to implement? -
ajitatif angajetor wrote:
ambiguouty (did I spell it correctly??)
No - ambiguity - close, though :-) Anyway - I've had a look through my code collection - I have a class that implements two
IDispatch
interfaces, in ATL 3.0 (it's an old VC6 project). Here's the relevant bit of the IDL:[ uuid(01b836c6-51c8-4476-bf15-ae91b0fe74f6), oleautomation, dual ] interface ICommands : IDispatch { [id(1), helpstring("method RereadEnvironment")] HRESULT RereadEnvironment(); }; [ hidden, uuid(0309A24D-B3E7-4C6A-8ACD-B3F0F8FAA483) ] coclass ApplicationEvents { [default] dispinterface IDispApplicationEvents; } [ uuid(6c5658bc-946b-4bc7-94bf-5530cad3d654) ] coclass Commands { [default] interface ICommands; };
and code
class ATL_NO_VTABLE CCommands : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CCommands, &CLSID_Commands>, public IDispatchImpl<ICommands, &IID_ICommands, &LIBID_DSWENVLib>, public IDispatchImpl<IApplicationEvents, &IID_IApplicationEvents, &LIBID_DSWENVLib> { BEGIN_COM_MAP(CCommands) COM_INTERFACE_ENTRY(ICommands) COM_INTERFACE_ENTRY2(IDispatch, ICommands) COM_INTERFACE_ENTRY(IApplicationEvents) END_COM_MAP() DECLARE_NOT_AGGREGATABLE(CCommands) <class continues>
Don't know if there's anything obvious there - the COM map looks very similar to yours - what about the inheritance? Do you have an
IDispatchImpl
inheritance for eachIDispatch
interface you want to implement?:-D uuuuuuh,no. I added an
IDispEventImpl
to inheritance list and it worked.Great help,thanks:) -
:-D uuuuuuh,no. I added an
IDispEventImpl
to inheritance list and it worked.Great help,thanks:)Cool - glad I could help :-)