Adding another IDispatch derived interface?
-
I cannot add a second interface (derived from IDispatch). I have a feeling I am doing something fundamentally wrong (like maybe it can't be done?). Here is the code: // TestDisp.idl : IDL source for TestDisp.dll // // This file will be processed by the MIDL tool to // produce the type library (TestDisp.tlb) and marshalling code. import "oaidl.idl"; import "ocidl.idl"; [ object, uuid(050877DD-6973-11D5-BF78-0050DA22A717), dual, helpstring("IObj1 Interface"), pointer_default(unique) ] interface IObj1 : IDispatch { [id(1), helpstring("method FirstMethod")] HRESULT FirstMethod(BSTR Junk); }; //Added: [ object, uuid(050877DD-6973-11D5-BF78-0050DA22A718), dual, helpstring("IObj2 Interface"), pointer_default(unique) ] //Added: interface IObj2 : IDispatch { [helpstring("method Method2")] HRESULT Method2(BSTR Crud); }; [ uuid(050877D0-6973-11D5-BF78-0050DA22A717), version(1.0), helpstring("TestDisp 1.0 Type Library") ] library TESTDISPLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(050877DE-6973-11D5-BF78-0050DA22A717), helpstring("Obj1 Class") ] coclass Obj1 { [default] interface IObj1; interface IObj2; //Added }; }; // Obj1.h : Declaration of the CObj1 #ifndef __OBJ1_H_ #define __OBJ1_H_ #include "resource.h" // main symbols ///////////////////////////////////////////////////////////////////////////// // CObj1 //< AND > Characters changed to [ and ], since I can't figure //out how to get them to display in a web page properly! class ATL_NO_VTABLE CObj1 : public CComObjectRootEx[CComSingleThreadModel], public CComCoClass[CObj1, &CLSID_Obj1], public IDispatchImpl[IObj1, &IID_IObj1, &LIBID_TESTDISPLib], public IDispatchImpl[IObj2, &IID_IObj2, &LIBID_TESTDISPLib] //Added (this creates the error) { public: CObj1() { } DECLARE_REGISTRY_RESOURCEID(IDR_OBJ1) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CObj1) COM_INTERFACE_ENTRY(IObj1) COM_INTERFACE_ENTRY(IObj2) //Added COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP() // IObj1 public: STDMETHOD(FirstMethod)(BSTR Junk); }; #endif //__OBJ1_H_ Here is the error I get: testdisp\obj1.h(28) : error C2594: 'static_cast' : ambiguous conversions from 'class CObj1 *' to 'struct IDispatch *':confused:
-
I cannot add a second interface (derived from IDispatch). I have a feeling I am doing something fundamentally wrong (like maybe it can't be done?). Here is the code: // TestDisp.idl : IDL source for TestDisp.dll // // This file will be processed by the MIDL tool to // produce the type library (TestDisp.tlb) and marshalling code. import "oaidl.idl"; import "ocidl.idl"; [ object, uuid(050877DD-6973-11D5-BF78-0050DA22A717), dual, helpstring("IObj1 Interface"), pointer_default(unique) ] interface IObj1 : IDispatch { [id(1), helpstring("method FirstMethod")] HRESULT FirstMethod(BSTR Junk); }; //Added: [ object, uuid(050877DD-6973-11D5-BF78-0050DA22A718), dual, helpstring("IObj2 Interface"), pointer_default(unique) ] //Added: interface IObj2 : IDispatch { [helpstring("method Method2")] HRESULT Method2(BSTR Crud); }; [ uuid(050877D0-6973-11D5-BF78-0050DA22A717), version(1.0), helpstring("TestDisp 1.0 Type Library") ] library TESTDISPLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(050877DE-6973-11D5-BF78-0050DA22A717), helpstring("Obj1 Class") ] coclass Obj1 { [default] interface IObj1; interface IObj2; //Added }; }; // Obj1.h : Declaration of the CObj1 #ifndef __OBJ1_H_ #define __OBJ1_H_ #include "resource.h" // main symbols ///////////////////////////////////////////////////////////////////////////// // CObj1 //< AND > Characters changed to [ and ], since I can't figure //out how to get them to display in a web page properly! class ATL_NO_VTABLE CObj1 : public CComObjectRootEx[CComSingleThreadModel], public CComCoClass[CObj1, &CLSID_Obj1], public IDispatchImpl[IObj1, &IID_IObj1, &LIBID_TESTDISPLib], public IDispatchImpl[IObj2, &IID_IObj2, &LIBID_TESTDISPLib] //Added (this creates the error) { public: CObj1() { } DECLARE_REGISTRY_RESOURCEID(IDR_OBJ1) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CObj1) COM_INTERFACE_ENTRY(IObj1) COM_INTERFACE_ENTRY(IObj2) //Added COM_INTERFACE_ENTRY(IDispatch) END_COM_MAP() // IObj1 public: STDMETHOD(FirstMethod)(BSTR Junk); }; #endif //__OBJ1_H_ Here is the error I get: testdisp\obj1.h(28) : error C2594: 'static_cast' : ambiguous conversions from 'class CObj1 *' to 'struct IDispatch *':confused:
Hi Dave, You are deriving a new class from two other classes that both implement IDispatch, therefore the compiler does not know which one to use. You can select which one should be implemented in your new class in your COM_MAP by using COM_INTERFACE_ENTRY2 instead of COM_INTERFACE_ENTRY: COM_INTERFACE_ENTRY(IObj1) COM_INTERFACE_ENTRY2(IDispatch, IObj2) //COM_INTERFACE_ENTRY(IDispatch) // Removed See the COM_INTERFACE_ENTRY2 docs. Hope this helps (and it is the correct answer :) Alwin Beukers