Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Adding another IDispatch derived interface?

Adding another IDispatch derived interface?

Scheduled Pinned Locked Moved COM
comc++helptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave_
    wrote on last edited by
    #1

    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:

    A 1 Reply Last reply
    0
    • D Dave_

      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:

      A Offline
      A Offline
      Alwin75
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups