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. How to access COM objects during runtime?

How to access COM objects during runtime?

Scheduled Pinned Locked Moved COM
c++comhelptutorialquestion
5 Posts 3 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
    dapipi
    wrote on last edited by
    #1

    Hi, I need to access COM objects during runtime or dynamically using VC++6. Can somebody please help me in this? Is there a way I can call the COM objects during runtime by entering the GUID or something like that? I am a beginner in COM.. Thx!!

    A A 3 Replies Last reply
    0
    • D dapipi

      Hi, I need to access COM objects during runtime or dynamically using VC++6. Can somebody please help me in this? Is there a way I can call the COM objects during runtime by entering the GUID or something like that? I am a beginner in COM.. Thx!!

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

      Is this the function you're looking for?

      CoCreateInstance(REFCLSID rclsid, 
                       LPUNKNOWN pUnkOuter, 
                       DWORD dwClsContext, 
                       REFIID riid,
                       LPVOID * ppv);
      

      I hope this helps you. -John

      1 Reply Last reply
      0
      • D dapipi

        Hi, I need to access COM objects during runtime or dynamically using VC++6. Can somebody please help me in this? Is there a way I can call the COM objects during runtime by entering the GUID or something like that? I am a beginner in COM.. Thx!!

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        I forgot to mention you might want to call CoIntialize(NULL) to initialize the COM runtime before making a call to CoCreateInstance(). Once you're through using your COM objects be sure and call CoUnitialize().

        1 Reply Last reply
        0
        • D dapipi

          Hi, I need to access COM objects during runtime or dynamically using VC++6. Can somebody please help me in this? Is there a way I can call the COM objects during runtime by entering the GUID or something like that? I am a beginner in COM.. Thx!!

          A Offline
          A Offline
          Abhishek Srivastava
          wrote on last edited by
          #4

          Hi there, :) One can access COM objects at run time , but the interface supported by this COM object should support IDispatch interface. CLSID objClsid; // initialize your obj CLSID in this variable using CoCreateInstance() get the IDispatch pointer. IDispatch *dispPtr; CoCreateInstance(objClsid, NULL, CLSCTX_ALL, IID_IDispatch , (void **) &dispPtr); if your object support IDispatch interface , it will return its instance , else it will return NULL. now using this dispPtr and IDispatch int isInfoAvailable; dispPtr->GetTypeInfoCount(&isInfoAvailable); if isInfoAvailable = 0 , that means this object does not provide run time type information of interfaces it supports. if isInfoAvailable = 1 , that mean now you can query for ITypeInfo interface pointer for getting information about the interface this object supports. now using GetTypeInfo() method you can further query for ITypeInfo interface , using which you can browse all the interface and methods of these interface supported by your COM object. and then using Invoke and GetIDsOfName methods of IDispatch you can also execute your method at run time. Regards Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

          D 1 Reply Last reply
          0
          • A Abhishek Srivastava

            Hi there, :) One can access COM objects at run time , but the interface supported by this COM object should support IDispatch interface. CLSID objClsid; // initialize your obj CLSID in this variable using CoCreateInstance() get the IDispatch pointer. IDispatch *dispPtr; CoCreateInstance(objClsid, NULL, CLSCTX_ALL, IID_IDispatch , (void **) &dispPtr); if your object support IDispatch interface , it will return its instance , else it will return NULL. now using this dispPtr and IDispatch int isInfoAvailable; dispPtr->GetTypeInfoCount(&isInfoAvailable); if isInfoAvailable = 0 , that means this object does not provide run time type information of interfaces it supports. if isInfoAvailable = 1 , that mean now you can query for ITypeInfo interface pointer for getting information about the interface this object supports. now using GetTypeInfo() method you can further query for ITypeInfo interface , using which you can browse all the interface and methods of these interface supported by your COM object. and then using Invoke and GetIDsOfName methods of IDispatch you can also execute your method at run time. Regards Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

            D Offline
            D Offline
            dapipi
            wrote on last edited by
            #5

            Thanks guys!!!

            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