How to: Embed Type Libraries as Win32 Resources in .NET-Based ApplicationsĀ
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
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:vbc /t:library MyApp.vb
csc /t:library MyApp.cs
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
Create a resource script that contains the following statement:
IDR_TYPELIB1 typelib "mytypelib.tlb"
For this example, the script file name is
myresource.rc
.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.Compile the source file again and specify the resource file. At the command prompt, type the following command:
vbc /t:library MyApp.vb /win32res:myresource.res
csc /t:library MyApp.cs /win32res:myresource.res
See Also
Concepts
Packaging an Assembly for COM
Exposing .NET Framework Components to COM