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. Instantiating another CoClass from a CoClass method in the same component

Instantiating another CoClass from a CoClass method in the same component

Scheduled Pinned Locked Moved COM
comquestion
3 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.
  • G Offline
    G Offline
    G Raven
    wrote on last edited by
    #1

    Dear fellow CPians, I have a simple COM component with two coclasses. I'd like to be able to instantiate one CoClass from a method of the other CoClass and be able to access the instantiated CoClasse's methods directly, and not through its interface (so I can supply it with some object data, not only basic data types). Is there a way to do this? There should be, as the two CoClasses are under the same application and library. I only know the CoCreateInstance method, but with this method I only have access to the interface for the new created object. Thanks in advance for your time with this. Best regards. G. Raven

    M 1 Reply Last reply
    0
    • G G Raven

      Dear fellow CPians, I have a simple COM component with two coclasses. I'd like to be able to instantiate one CoClass from a method of the other CoClass and be able to access the instantiated CoClasse's methods directly, and not through its interface (so I can supply it with some object data, not only basic data types). Is there a way to do this? There should be, as the two CoClasses are under the same application and library. I only know the CoCreateInstance method, but with this method I only have access to the interface for the new created object. Thanks in advance for your time with this. Best regards. G. Raven

      M Offline
      M Offline
      Milton Karimbekallil
      wrote on last edited by
      #2

      Yes, U can use CComObject class for this. Suppose u have a collection class CTables of CTable. CTables has a method called Item which is supposd to rtn a CTable object and we need to initialize a private member called Ordinal in CTable. So the Item method of CTables will be STDMETHODIMP CTables::Item(ITable **pT) { CComObject *objTable; objTable->CreateInstance(&objTable); objTable->Ordinal = 117; *pT= NULL; objTable->QueryInterface(IID_ITable, reinterpret_cast<void**>(pT) ); return S_OK; } does this make sence....mil10

      G 1 Reply Last reply
      0
      • M Milton Karimbekallil

        Yes, U can use CComObject class for this. Suppose u have a collection class CTables of CTable. CTables has a method called Item which is supposd to rtn a CTable object and we need to initialize a private member called Ordinal in CTable. So the Item method of CTables will be STDMETHODIMP CTables::Item(ITable **pT) { CComObject *objTable; objTable->CreateInstance(&objTable); objTable->Ordinal = 117; *pT= NULL; objTable->QueryInterface(IID_ITable, reinterpret_cast<void**>(pT) ); return S_OK; } does this make sence....mil10

        G Offline
        G Offline
        G Raven
        wrote on last edited by
        #3

        Thank you very much, Mil10. This makes perfect sense and is exactly what I was looking for. Regards. G. Raven

        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