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 Rreference COM object(tlb file) in VC++

How to Rreference COM object(tlb file) in VC++

Scheduled Pinned Locked Moved COM
comc++tutorial
10 Posts 5 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.
  • J Offline
    J Offline
    Jahnson K
    wrote on last edited by
    #1

    Hi All, I have generated a tlb file through idl for the implementation of COM. I want to use this COM object in my VC++ code. Anybody know how to reference tlb file in VC++ code. For VB I can directly reference the tlb file, but I dont dont know is there any way we can reference tlb file in my VC++ code and start using the methods inside COM object Thanks in Advance JK

    L P U 3 Replies Last reply
    0
    • J Jahnson K

      Hi All, I have generated a tlb file through idl for the implementation of COM. I want to use this COM object in my VC++ code. Anybody know how to reference tlb file in VC++ code. For VB I can directly reference the tlb file, but I dont dont know is there any way we can reference tlb file in my VC++ code and start using the methods inside COM object Thanks in Advance JK

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use #import[^] to import TypeLibrary(.TLB file)

      Sohail

      J 1 Reply Last reply
      0
      • L Lost User

        Use #import[^] to import TypeLibrary(.TLB file)

        Sohail

        J Offline
        J Offline
        Jahnson K
        wrote on last edited by
        #3

        Thanks Sohail, Thanks for the good article. I will implement and see. Thanks JK

        L 1 Reply Last reply
        0
        • J Jahnson K

          Thanks Sohail, Thanks for the good article. I will implement and see. Thanks JK

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          OK. Let me know if you have further problems with this. Cheers,

          Sohail

          1 Reply Last reply
          0
          • J Jahnson K

            Hi All, I have generated a tlb file through idl for the implementation of COM. I want to use this COM object in my VC++ code. Anybody know how to reference tlb file in VC++ code. For VB I can directly reference the tlb file, but I dont dont know is there any way we can reference tlb file in my VC++ code and start using the methods inside COM object Thanks in Advance JK

            P Offline
            P Offline
            pnpfriend
            wrote on last edited by
            #5

            You have to import the tlb file to ur VC++ I declare it in header file. #import "C:\myDll\mydll.tlb" raw_interface_only ... .. public Void INiComObj() { CoInitialize(NULL); HRESULT hr = CocreateInstance(CLSID...) }

            J 1 Reply Last reply
            0
            • P pnpfriend

              You have to import the tlb file to ur VC++ I declare it in header file. #import "C:\myDll\mydll.tlb" raw_interface_only ... .. public Void INiComObj() { CoInitialize(NULL); HRESULT hr = CocreateInstance(CLSID...) }

              J Offline
              J Offline
              Jahnson K
              wrote on last edited by
              #6

              Hi Sohail, Thanks for the good article. And thanks to pnp for giving the sample code. I did import my tlb file with raw_interface_only option. #import "C:\temp\Mytlb.tlb" raw_interface_only I am facing following compilation error in *.tlh file. error C2504: 'AnyObject' : base class undefined When I see my tlh file my class is deriving from AnyObject base class. I am not sure why it is deriving from AnyObject? Is there any base class "AnyObject" in C++? If yes what are the include files i need to include? Please help me. Thanks in advance. Regards JK

              J 1 Reply Last reply
              0
              • J Jahnson K

                Hi Sohail, Thanks for the good article. And thanks to pnp for giving the sample code. I did import my tlb file with raw_interface_only option. #import "C:\temp\Mytlb.tlb" raw_interface_only I am facing following compilation error in *.tlh file. error C2504: 'AnyObject' : base class undefined When I see my tlh file my class is deriving from AnyObject base class. I am not sure why it is deriving from AnyObject? Is there any base class "AnyObject" in C++? If yes what are the include files i need to include? Please help me. Thanks in advance. Regards JK

                J Offline
                J Offline
                Jahnson K
                wrote on last edited by
                #7

                Hi All, I found out the solution for error C2504: 'AnyObject' : base class undefined My tlb is dependent on some other tlb so, what i did is I #import the base tlb before importing my tlb. It complies fine. There are no errors. But, I am not able to get pointer to my COM object, when I am running following sample code CoInitialize(NULL); IMyComObject pObject(_uuidof(MyComObjectName)); I am getting following error in CoCreateInstance method 0x80040154 Class Not Registered I checked the registry, there is an entry for my typelib. I am not sure why it is not able find the class. Any suggestions/help please.. Thanks in advance JK

                V 1 Reply Last reply
                0
                • J Jahnson K

                  Hi All, I found out the solution for error C2504: 'AnyObject' : base class undefined My tlb is dependent on some other tlb so, what i did is I #import the base tlb before importing my tlb. It complies fine. There are no errors. But, I am not able to get pointer to my COM object, when I am running following sample code CoInitialize(NULL); IMyComObject pObject(_uuidof(MyComObjectName)); I am getting following error in CoCreateInstance method 0x80040154 Class Not Registered I checked the registry, there is an entry for my typelib. I am not sure why it is not able find the class. Any suggestions/help please.. Thanks in advance JK

                  V Offline
                  V Offline
                  Vi2
                  wrote on last edited by
                  #8

                  Jahnson K wrote:

                  I am getting following error in CoCreateInstance method 0x80040154 Class Not Registered

                  The TLB describes the all data of COM server, but there is no code in TLB. You should also register COM server, i.e. EXE or DLL executable module.

                  With best wishes, Vita

                  J 1 Reply Last reply
                  0
                  • J Jahnson K

                    Hi All, I have generated a tlb file through idl for the implementation of COM. I want to use this COM object in my VC++ code. Anybody know how to reference tlb file in VC++ code. For VB I can directly reference the tlb file, but I dont dont know is there any way we can reference tlb file in my VC++ code and start using the methods inside COM object Thanks in Advance JK

                    U Offline
                    U Offline
                    User 3828380
                    wrote on last edited by
                    #9

                    there are two ways 1)Use #import second you can use the class wizard and refer the tlb file, the wizard will generate the .cli and .clh file containing the wrapper around your COM component Regards, Sunil Tonger

                    1 Reply Last reply
                    0
                    • V Vi2

                      Jahnson K wrote:

                      I am getting following error in CoCreateInstance method 0x80040154 Class Not Registered

                      The TLB describes the all data of COM server, but there is no code in TLB. You should also register COM server, i.e. EXE or DLL executable module.

                      With best wishes, Vita

                      J Offline
                      J Offline
                      Jahnson K
                      wrote on last edited by
                      #10

                      Thank you all, I am able to get the COM object. There was couple of mistates I was doing while creating CoCreateInstance. Now it works fine. Thanks JK

                      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