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 reference tlb file in VC++

How to reference tlb file in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
comc++tutorial
4 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.
  • 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 Reply·

    A 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 Reply·

      A Offline
      A Offline
      Arman S
      wrote on last edited by
      #2

      Using .tlb in C++ is not so straightforward as in VB, but possible. Generally, the following example may guide you how to use type libraries in VC++;

      #import "MyPath\MyTypeLib.tlb" rename_namespace("SmthLooksMeNice") using namespace SmthLooksMeNice;
      #include <objbase.h>

      int main()
      {
      CoInitialize(NULL);

      // Assume your COM object is named MyComObjectName
      // and there is an interface IMyComObject.
      // #import generated a smart pointer over that interface.
      IMyComObjectPtr pObject(_uuidof(MyComObjectName));

      BSTR temp = pObject->SomeProp;
      pObject->DoSmth();
      //...
      CoUninitialize();
      return 0;
      }

      -- ===== Arman

      J 1 Reply Last reply
      0
      • A Arman S

        Using .tlb in C++ is not so straightforward as in VB, but possible. Generally, the following example may guide you how to use type libraries in VC++;

        #import "MyPath\MyTypeLib.tlb" rename_namespace("SmthLooksMeNice") using namespace SmthLooksMeNice;
        #include <objbase.h>

        int main()
        {
        CoInitialize(NULL);

        // Assume your COM object is named MyComObjectName
        // and there is an interface IMyComObject.
        // #import generated a smart pointer over that interface.
        IMyComObjectPtr pObject(_uuidof(MyComObjectName));

        BSTR temp = pObject->SomeProp;
        pObject->DoSmth();
        //...
        CoUninitialize();
        return 0;
        }

        -- ===== Arman

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

        Hi Arman, Thanks for the sample code I did import my tlb file with rename_namespace("MYNAMESPACE") option I got following two compilation errors 1) error C2664: '_com_issue_errorex' : cannot convert parameter 2 from MYNAMESPACE::MYCLASS *const ' to 'IUnknown *' 2) error C2504: 'AnyObject' : base class undefined I tried import using following command #import "C:\temp\Mytlb.tlb" rename_namespace("MYNAMESPACE") raw_interface_only The first compliation error went off but the second error error C2504: 'AnyObject' : base class undefined still exists. 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 called "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 Arman, Thanks for the sample code I did import my tlb file with rename_namespace("MYNAMESPACE") option I got following two compilation errors 1) error C2664: '_com_issue_errorex' : cannot convert parameter 2 from MYNAMESPACE::MYCLASS *const ' to 'IUnknown *' 2) error C2504: 'AnyObject' : base class undefined I tried import using following command #import "C:\temp\Mytlb.tlb" rename_namespace("MYNAMESPACE") raw_interface_only The first compliation error went off but the second error error C2504: 'AnyObject' : base class undefined still exists. 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 called "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
          #4

          Hi Arman, 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

          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