TIP: Adding a typelibrary as a resource to a project

There may be occasions when you inherit a project that does not have the typelibrary compiled as a resource into the module that implements your COM object (be it a COM server, ActiveX etc.). In such a situation, a lot of people are left wondering how to make the typelibrary part of the module's resource instead of distributing the .TLB file separately.

The solution is really simple:

Step A) Open the project's .rc file as text (i.e. select 'Text' in the 'Open As' combo-box on the 'Open' dialog.)

Step B) In the portion of the file where all the TEXTINCLUDE's are defined, add the following lines


3 TEXTINCLUDE DISCARDABLE 
BEGIN"1 TYPELIB 
""ProjectName.tlb""\r\n"
"\0"END
Note: Make sure that the number on the TEXTINCLUDE DISCARDABLE line is one greater than the highest number for the TEXTINCLUDE lines in that file.

Step C) At the bottom of the project's .rc file, add the following lines


#ifndef APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// 
//
// Generated from the 
TEXTINCLUDE 3 resource.
// 
1 TYPELIB "ProjectName.tlb" 

///////////////////////////////////////////////////////////////////////////// 
#endif // not APSTUDIO_INVOKED

Note: Ensure that the number on the TYPELIB "ProjectName.tlb" line is adjusted to be one greater than any other TYPELIB resource in the file (This seems unlikely given the fact that one would include only the .TLB for the project in question.)

That's all. Compile and link the project and open up the module in the OLE/COM Viewer to ensure that the TLB is actually part of the project. Removing the TLB as a resource from a project.

It should be obvious from the earlier discussion that one just needs to delete the lines mentioned in Steps B and C from the project's .rc file in order to remove the typelibrary as a resource from the project.

IT Offers

Comments

  • Nike Draught Max+instagram, wishes you contain the color to step on your feet!

    Posted by madytreathy on 04/24/2013 05:15pm

    Call to mind in 2008, if not earlier, when Nike launched up ahead of the independent shoe color projects, the catchword "Bound Your Colours", "Nike PhotoiD" scheme, [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] reply has not been as enthusiastic as expected. Have in mind, 2008 Canon IXUS 80 IS Digital greetings card arcade but only 8 million pixels, Nokia, the plastic phone market is the at worst leadership, NikeiD was boost to color in the photos as a essence quest of sneakers excise color, although provocative, but does bother some. Instagram which make this item hold up to ridicule and fundamental, Nike PHOTOiD homeopathic upgrade customization services, recently [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache free[/url] released a strange plan. That such iD can you implement pictures as instagram account shoe color, little while offer Nike Mood Max shoes and Nike Puff Max 1, Nike Air Max 90 953 options. Interested in children's shoes, you [url=http://northernroofing.co.uk/roofins.cfm]nike free run[/url] can ever vanish into thin air's official website photoid.Nike.com, in addition to skim through other people's originative charge, or you can hear to upload your own instagram photo, build your own Nike Hauteur Max.

    Reply
  • Other way also!!! a question also?

    Posted by Legacy on 12/16/2003 12:00am

    Originally posted by: Nitin Band

    open the project in VC,
    go to Menu Bar, select Insert->Resource
    Box pops up, select the "TYPELIB".
    Click "Import" button, and select the .tlb u want to import.
    Select "TYPELIB" again as Custom Resource type.

    That's it, it makes necessary changes to resource.h and .rc files.

    Use AfxOleRegisterTypeLib(AfxGetInstanceHandle(), LIBID_URTypeLib); in InitInstance().

    where LIBID_URTypeLib has been defined as the id of the type library.

    Whether this has got any other significance, I will like to know

    Reply
  • It's easier than that!

    Posted by Legacy on 02/24/1999 12:00am

    Originally posted by: Pete Burgess

    In DevStudio, select the Resource tab in the Workspace, right-click the resource folder and choose "Resource includes...".

    In this dialog add the following line to the "Compile time directives" edit box:

    1 TYPELIB "TypeLibName.tlb"

    OK the dialog, save the resource file. DevStudio writes the .rc file with the next sequencial TEXTINCLUDE number and adds the appropriate lines to the #ifdef at the bottom too.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds