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. C / C++ / MFC
  4. How to Expose two COM interfaces

How to Expose two COM interfaces

Scheduled Pinned Locked Moved C / C++ / MFC
comhardwareoophelptutorial
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.
  • A Offline
    A Offline
    Alois Kraus
    wrote on last edited by
    #1

    Hello, I have an ActiveX Control which is embedded in another application which works fine. The only problem is that some peers want to test the control in the application before we ship the product. From my point of view: Automated Tests = COM, so I came up with the idea to make a second COM interface and register it in the ROT (Running Obect table). This Interface gives full access to my ActiveX control. I have not done this before so I would like get some opinions how this could be done in the best object oriented way. Can I use the same .ODL file for my ActiveX project and insert there the second interface ? What must I do to implement a second COM interface by myself ? Yours, Alois Kraus

    P 1 Reply Last reply
    0
    • A Alois Kraus

      Hello, I have an ActiveX Control which is embedded in another application which works fine. The only problem is that some peers want to test the control in the application before we ship the product. From my point of view: Automated Tests = COM, so I came up with the idea to make a second COM interface and register it in the ROT (Running Obect table). This Interface gives full access to my ActiveX control. I have not done this before so I would like get some opinions how this could be done in the best object oriented way. Can I use the same .ODL file for my ActiveX project and insert there the second interface ? What must I do to implement a second COM interface by myself ? Yours, Alois Kraus

      P Offline
      P Offline
      peterchen
      wrote on last edited by
      #2

      There are two basic ways to expose a secondary interface: a) local classes (MFC does that, including some dirty tricks to make this effective) b) multile inheritance (ATL does that) b) is IMO much cleaner, only you can get into problems with method name clashes Some pseudocode for the latter:

      class CCoImpl : public IFun, public ITest
      {
      HRESULT QueryInterface()
      {
      if (iid == IUnknown) { // always return the same pointer when specifically asked for IUnk; which one doesn't matter
      addref, return static_cast(this);
      }
      if (iid == IFun) {
      addref, return static_cast(this);
      }
      if (iid == ITest) {
      addref, return static_cast(this);
      }
      return E_NOINTERFACE;
      }
      // IFun methods:
      HRESULT GoShopping() { ... }
      HRESULT GoRocking() { ... }

      // ITest Methods
      HRESULT TestCountShoes(....) { ... }
      };

      you get the idea... Neither way you can expose two dispatch (or dual) interfaces - you can only have obe dispatch-based interface per object.


      If I could find a souvenir / just to prove the world was here   [sighist]

      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