Skip to content

Type Library Importer in Managed Code

Latest
Compare
Choose a tag to compare
@jozefizso jozefizso released this 13 Oct 22:14
· 7 commits to master since this release
v1.0.0

TLBIMP is a .NET SDK tool that creates an Interop assembly from a COM type library.
This project is a managed code implementation of TLBIMP. We have released this tool
so developers can see what TLBIMP does and if necessary extend the tool for their
specific requirements, while this is the third Tlbimp release on CodePlex.

A big feature is added to this release: Tlbimp output customization
With this feature, some special needs of importing convention can be handled when
a type library is being imported by creating a configuration file in xml format,
instead of leaving it later by disassembling an interop assembly to update the code.
The current version supports the following configuration action:

  • ChangeManagedName: To provide a tlb type with a customized managed name instead of the default one.
  • ResolveTo: To resolve a tlb type to a user-specified managed type.
  • AddAttribute: To add some customized attribute to the corresponding managed types of the tlb types.
  • PreserveSig: To apply PreserveSig attribute to a managed function instead of [out, retval] parameters.
  • ConvertTo: To convert a tlb function parameter to the user-specified managed signature.

The new Tlbimp in the package accept the following command-line syntax to integrate the customized rule into its importing process:

> tlbimp ATlb.tlb /config:AXMLConfigFile.xml

A UI tool, TlbimpRuleFileEditor, can be found in the package for customization purpose,
which help to create a configuration file without requiring knowledge of xml configuration
file syntax. More introduction can be found in the document attached with the project.

The package also includes some tests, which can be used with Tlbimp Regression Test Tool
(attached in the package as well) to validate any updates made against the original source
code. More information about this tool can be found in the document in the package.

Other features introduced in the previous releases, are two command-line switches as the follows:

  • /v2: When this switch is on, the Tlbimp applies new rules when importing native types so as to get the output more as expected result. The new rule in this release is to convert VARIANT_BOOL in structures to bool instead of short.
  • /PreserveSig: If this swtich is applied, the Tlbimp doesn't apply [out, retval] parameter transformation but adds PreserveSigAttribute to the imported method.

To get the help for the command-line tool, please type in "tlbimp /?" in the command line, or check MSDN document library for the features in .NET 3.5 SDK.

Update: Ported some bug fixes from Tlbimp in .NET framework v4.0