Thursday, December 25, 2008

Interoperating with COM - Using COM from the .NET Framework (2)

How to Import a Type Library Using the Type Library Importer (Tlbimp.exe)

You can use the Type Library Importer (Tlbimp.exe) to create an interop assembly which will allow your .NET application to use a type defined in it.

How to use Tlbimp.exe:
  1. Open a Visual Studio Command Prompt (under the "Visual Studio Tools" menu of the "Start" menu)
  2. Use "Tlbimp.exe /?" or "Tlbimp /help" to see the usage message.
  3. Sample:
    Tlbimp.exe C:\test\MSO9.dll (By default, it will generate the file base on the name of the type library contained within the original COM dll file.)
    Tlbimp.ee C:\test\MSO9.dll /out:NewNameOffice.dll (Or you can use /out to specify the name of output file.)
  4. The namespace of the imported library uses the same name as that of the library from which it was created by default. You can use this to change the namespace:
    Tlbimp.exe MSO9.dll /namespace:MyNewNameSpace

After you create the new assembly dll by using Tlbimp.exe, you can then add a reference to it and use the types just as you would use a native .NET Framework type.

For more information about Tlbimp.exe, you can visit here: http://msdn.microsoft.com/en-us/library/tt0cf3sx.aspx

No comments:

Post a Comment