Using a Type Library to Build an Interop Assembly

To be sure, the VB6 compiler generates many other IDL attributes under the hood, and you see additional bits and pieces where appropriate. However, at this point, I am sure you are wondering exactly why I spent the last several pages describing the COM IDL. The reason is simple: when you add a reference to a COM server using Visual Studio 2008, the IDE reads the type library to build the corresponding interop assembly. While VS 2008 does a very good job of generating an interop assembly, the Add Reference dialog box follows a default set of rules regarding how the interop assembly will be constructed and does not allow you to fine-tune this construction.

If you require a greater level of flexibility, you have the option of generating interop assemblies at the command prompt, using a .NET tool named tlbimp.exe (the type library importer utility). Among other things, tlbimp.exe allows you to control the name of the .NET namespace that will contain the types and the name of the output file. Furthermore, if you wish to assign a strong name to your interop assembly in order to deploy it to the GAC, tlbimp.exe provides the /keyfile flag to specify the *.snk file (see Chapter 15 for details regarding strong names). To view all of your options, simply type tlbimp at a Visual Studio 2008 command prompt and hit the Enter key, as shown in Figure 19-12.

ÜB Administrator: Visual Studio 2008 Command Prompt

Setting environment for using Microsoft Visual Studio 2008 x86 tools.

\Program Fi 1es\Microsoft Visual Studio 9.0\VC>tlbimp Microsoft (R) .NET Framework Type Library to Assembly Converter 3.5.21022.8 Copyright (C) Microsoft Corporation. All rights reserved.

Syntax: Tlblmp TypeLi bName Opti ons:

/out:Ft 1eName /namespace:Namespace /asmversi on¡Version /reference:Fi1eName /tlbreference:Fi1eName /publi ckey:Fi1eName /keyfi1e:Fi1eName /keycontai ner:Fi1eName /delaysi gn /unsafe

/noclassmembers /noloao

[Opti ons]

File name of assembly to be produced Namespace of the assembly to be produced Version number of the assembly to be produced File name of assembly to use to resolve references File name of typelib to use to resolve references File containing strong name public key File containing strong name key pair Key container holding strong name key pair Force strong name delay signing

Produce interfaces without runtime security checks Prevents Tlbimp from adding members to classes Prevents Tlblmo from disolavina loao

0 0

Post a comment

  • Receive news updates via email from this site