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. ATL / WTL / STL
  4. Using QueryInterface inside a COM

Using QueryInterface inside a COM

Scheduled Pinned Locked Moved ATL / WTL / STL
comooptutorialquestion
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
    donguy76
    wrote on last edited by
    #1

    Hello I am working on a COM project in which i use Interface Inheritance. The IDL file looks like this, interface IEarthInterface : IUnknown {}; interface IOceanInterface : IEarthInterface {}; interface IPacificInterface : IOceanInterface {}; interface IAntarticInterface : IOceanInterface {}; interface IDataInterface : IUnknown {}; interface IFindInterface : IDataInterface { HRESULT GetOceanTypeInterface(IOceanInterface** pOceanInterface); }; From inside IFindInterface i need to figure out which Ocean is currently attached and then attach or typecast it was IOceanInterface and send it back to client. All i wanted to know is how to get a Interface pointer from inside another Interface. ie, can i call CoCreateInstance or QueryInterface from inside IFindInterface and get the Interface Pointer to IPacificInterface or IAntarticInterface. I been already told that CoCreateInstance will not work in this case. Any idea how to implement this? Thanks in advance.

    D 1 Reply Last reply
    0
    • D donguy76

      Hello I am working on a COM project in which i use Interface Inheritance. The IDL file looks like this, interface IEarthInterface : IUnknown {}; interface IOceanInterface : IEarthInterface {}; interface IPacificInterface : IOceanInterface {}; interface IAntarticInterface : IOceanInterface {}; interface IDataInterface : IUnknown {}; interface IFindInterface : IDataInterface { HRESULT GetOceanTypeInterface(IOceanInterface** pOceanInterface); }; From inside IFindInterface i need to figure out which Ocean is currently attached and then attach or typecast it was IOceanInterface and send it back to client. All i wanted to know is how to get a Interface pointer from inside another Interface. ie, can i call CoCreateInstance or QueryInterface from inside IFindInterface and get the Interface Pointer to IPacificInterface or IAntarticInterface. I been already told that CoCreateInstance will not work in this case. Any idea how to implement this? Thanks in advance.

      D Offline
      D Offline
      Dennis Gourjii
      wrote on last edited by
      #2

      This should work: IPacificInterface* pPacific = NULL; pOceanInterface->QueryInterface(NULL, IID_IPacificInterface, &pPacific); If this fails, try all other possible derived interfaces until a call to QueryInterface succeeds. This is pretty much like using dynamic_cast to determine the type of object by pointer or reference to base.

      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