TIP: Adding a typelibrary as a resource to a project | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 18, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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""rn"
""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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.