This documentation is archived and is not being maintained.

How to: Embed Type Libraries as Win32 Resources in .NET-Based Applications

Updated: May 2010

You can package a type library as a separate file or embed it as Win32 resource file within a .NET-based application. Microsoft Visual Basic 6.0 performed this task for you automatically; however, when using Microsoft Visual Basic 2005, you must embed your type library manually.

To embed a type library as a Win32 resource in a .NET-based application

  1. Compile your managed application as a library file. For example, to create an assembly for an application called MyApp, type the following command at the command prompt:

    csc /t:library MyApp.cs
  2. Export a type library file from your assembly using the Type Library Exporter (Tlbexp.exe). At the command prompt, type the following command:

    tlbexp MyApp.dll /out:mytypelib.tlb
  3. Create a resource script that contains the following statement:

    1 typelib "mytypelib.tlb"

    For this example, the script file name is myresource.rc.

  4. Compile the script using the Microsoft Windows Resource Compiler (Rc.exe). At the command prompt, type the following command:

    rc myresource.rc

    Rc.exe produces the myresource.res resource file.

  5. Compile the source file again and specify the resource file. At the command prompt, type the following command:

    csc /t:library MyApp.cs /win32res:myresource.res




May 2010

Corrected the resource script content in step 3.

Content bug fix.