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 inerface with COM Objects?

How to inerface with COM Objects?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomtutorial
7 Posts 4 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
    Divyang Mithaiwala
    wrote on last edited by
    #1

    Can any body tell me how can i inerface with any COM object? I know GUID/CLSID of he object. I am new with COM Object.

    C S V 3 Replies Last reply
    0
    • D Divyang Mithaiwala

      Can any body tell me how can i inerface with any COM object? I know GUID/CLSID of he object. I am new with COM Object.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The easiest way is to #import the COM object and use __uuidof to generate instances. If you google __uuidof, you're bound to find heaps of examples. Remember, the objects need to be registered on your machine, if you just have been given them as files, you can't just dump them in a folder. regsvr32 is the command line command to register a COM object. If it's installed with something ( like Office ), then this has been done for you. Christian Graus - Microsoft MVP - C++

      D 1 Reply Last reply
      0
      • D Divyang Mithaiwala

        Can any body tell me how can i inerface with any COM object? I know GUID/CLSID of he object. I am new with COM Object.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        There are various libraries that provide classes (and such) to make dealing with COM easier like ATL and the compiler provided COM support classes. Given that you haven't provided much info on this I'll point to at some APIs/interfaces: CoInitialize - To initialize COM on the current thread. CoCreateInstance - Create a registered COM object given a CLSID. IUnknown::QueryInterface - Get an interface on a COM object given its IID. IDispatch - For dispatch interfaces. If you're not driving IDispatch interface you will need to have a header file so you can call the methods on the interfaces. There are many ways to do this: - Use one that comes with the component or SDK - Use #import - If you've got an IDL file, use MIDL to make one. - Use a tool like OleView to make one. Steve

        D 1 Reply Last reply
        0
        • C Christian Graus

          The easiest way is to #import the COM object and use __uuidof to generate instances. If you google __uuidof, you're bound to find heaps of examples. Remember, the objects need to be registered on your machine, if you just have been given them as files, you can't just dump them in a folder. regsvr32 is the command line command to register a COM object. If it's installed with something ( like Office ), then this has been done for you. Christian Graus - Microsoft MVP - C++

          D Offline
          D Offline
          Divyang Mithaiwala
          wrote on last edited by
          #4

          thank u i try for it.

          1 Reply Last reply
          0
          • S Stephen Hewitt

            There are various libraries that provide classes (and such) to make dealing with COM easier like ATL and the compiler provided COM support classes. Given that you haven't provided much info on this I'll point to at some APIs/interfaces: CoInitialize - To initialize COM on the current thread. CoCreateInstance - Create a registered COM object given a CLSID. IUnknown::QueryInterface - Get an interface on a COM object given its IID. IDispatch - For dispatch interfaces. If you're not driving IDispatch interface you will need to have a header file so you can call the methods on the interfaces. There are many ways to do this: - Use one that comes with the component or SDK - Use #import - If you've got an IDL file, use MIDL to make one. - Use a tool like OleView to make one. Steve

            D Offline
            D Offline
            Divyang Mithaiwala
            wrote on last edited by
            #5

            But i have no idea of working with IUnknown. I read so much about this interface in MSDN.

            S 1 Reply Last reply
            0
            • D Divyang Mithaiwala

              But i have no idea of working with IUnknown. I read so much about this interface in MSDN.

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              IUnknown has only three methods:  QueryInterface: Get an interface on an object.  AddRef: Call when you copy an interface pointer.  Release: Call when you destroy an interface pointer. I think you should read a good COM tutorial. Steve

              1 Reply Last reply
              0
              • D Divyang Mithaiwala

                Can any body tell me how can i inerface with any COM object? I know GUID/CLSID of he object. I am new with COM Object.

                V Offline
                V Offline
                vallikumar
                wrote on last edited by
                #7

                Hi, To start COM application, you have to know some thing about COM and Interfaces. In VC++, we can do it two ways 1. Using MFC and 2) Using ATL libraries. ATL is simple and wizard faced. All interfaces creation and registration take care by ATL wizards. But in case if MFC, you have to inherit a class from CCmdTarget and create a interface also from IUnknown and IDispatch based upon your need. If you are going to work with on languages like VC++, VB etc then IUnkonwn is enough. But if your COM should support with script languages like VB script, Jscript then You shound use IDispatch. To create simple MFC COM, please go through the below MSDN link.. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomg/html/msdn\_house2.asp best of luck regards Vallikumar A

                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