Exploring the .NET Interop Tools

The .NET Framework provides many tools for runtime as well as Visual Studio .NET (VS .NET) users. We'll use VS .NET for the applications in this chapter, but it doesn't hurt to take a look at these options. It's easy to convert a COM library into a .NET assembly using these tools. There are three different ways to do so.

Using Visual Studio .NET

VS .NET provides a pretty simple way to import a type library in a managed application. The Project Add Reference menu option allows you to access a COM library and add it to the project. This adds a namespace to the project, so you can access the library members through that namespace.

Using the Type Library Importer and Exporter (Tlbimp.exe)

The Type Library Importer, known as Tlbimp or Tlbimp.exe, is a command-line utility to convert a COM type library into a .NET assembly. Why a command-line utility? Well, this is an obvious question if you're using VS. You can ignore this option if you use VS.NET for your development. This option is useful for developers who don't have VS.NET.

Tlbimp.exe takes as a minimum one argument, the filename of the COM type library that you want to convert to an equivalent .NET Runtime assembly. The output of Tlbimp.exe is a binary file that contains runtime metadata for the types defined in the original COM type library.

This is the syntax:

 tlbimp tlbFile [options] 

where tlbFile is the name of the COM type library.

Table 20-1 describes some of the Tlbimp.exe options.

Table 20-1: Tlbimp.exe Options




Specifies the version of the assembly to produce


Displays the available help commands


Specifies the namespace in which to produce the assembly


Specifies the name of output assembly


Specifies the namespaces to use to resolve references to types defined outside the current type library


Displays syntaxes and options for the tool

You can find Tlbimp.exe in the FrameworkSDK\Bin directory of your VS .NET or .NET Software Development Kit (SDK) installation.

Using the Type Library Exporter (Tlbexp.exe)

The Type Library Exporter (Tlbexp.exe) does the reverse job of Tlbimp.exe. It generates an equivalent type library for a .NET assembly. This utility is useful when you need to use a managed code assembly in unmanaged code. Similar to Tlbimp, this utility also has options. The default command is as follows:

 tlbexp assemblyName 

where assemblyName is the name of the assembly for which you want to convert an equivalent type library.

Table 20-2 describes some of the options.

Table 20-2: Tlbexp.exe Options




Shows command syntax and options.


Specifies the name of the type library to generate equivalent to an assembly. If there are no options, the default name of the type library is the same as the assembly.


Shows command syntax and options.

You can find Tlbexp.exe in the FrameworkSDK\Bin directory of your VS .NET or .NET SDK installation.


You can't use Tlbexp.exe to produce a type library from an assembly that was imported using Tlbimp.exe.

Applied ADO. NET(c) Building Data-Driven Solutions
Applied ADO.NET: Building Data-Driven Solutions
ISBN: 1590590732
EAN: 2147483647
Year: 2006
Pages: 214

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net