How To Add Type Libraries as Resources to .dll and .exe Files (122285)



The information in this article applies to:

  • Microsoft OLE Libraries for Windows 95, Windows NT 3.51, and Win32s

This article was previously published under Q122285
You can add a type library as a resource to an .exe or .dll file by using the following statement in the .rc file:

1 typelib Test.tlb

Test.tlb is the type library to be added as a resource.

If a type library is added as a resource, a separate .tlb file need not be shipped with the application. LoadTypeLib() and LoadRegTypeLib() can be used to load the type library from the .exe or .dll file in which it exists as a resource.

NOTE: OLE version 2.02 or higher is needed to read a type library from an .exe file.

An .exe or .dll file can contain multiple typelib resources. For example:

1 typelib Test1.tlb
2 typelib Test2.tlb

Test1.tlb and Test2.tlb are type libraries to be added as resources.

By default, LoadTypeLib extracts the type library from the first resource of type typelib. To load a different type library resource, append an integer index to the szFileName parameter of LoadTypeLib. For example:

LoadTypeLib(OLESTR("c:\\test.exe\\2"), &ptlib);

This statement loads the type library resource 2 from Test.exe.

Modification Type:MinorLast Reviewed:3/3/2005
Keywords:kbhowto KB122285