Friday, 27 June 2008

Manually creating Interop dll using tlbimp.exe

Visual Studio .Net automatically creates Interop dll when you reference the COM dll in your project. This is all nice and behaves as expected, but at times you may want to create the Interop dll manually.

Tlbimp.exe is the tool to use. However, strange as it may seems, by default it doesn't do what Visual Studio does. How interesting ...

Visual Studio .Net by default add "Interop." at the beginning of the generated Interop dll and set the namespace as the name of the dll sans the ".dll".

For example, if the dll is called MyCOM.dll. Visual Studio generates: Interop.MyCOM.dll and creates the Interop dll under MyCOM namespace.

To achieve the same effect using tlbimp, you need to use both the /out and /namespace flag. For example:

tlbimp /out:Interop.MyCOM.dll /namespace:MyCOM MyCOM.dll

Sorted.

0 comments: