Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Extract TypeLib from a COM exe on Command Line

I've recently had need to produce an interop assembly. After some googling I discovered tlbimp.exe. My next problem was that my COM library did not come with a .tlb file. Further googling revealed that the type lib is often included as a resource in an exe/dll. Sure enough, opening the exe in VS2010 revealed it's type lib and a right-click later I had a tlb file to use with tlbimp. Awesome.

However this is not a very nice process. Should I need to do this in the future, is there a way of extracting a Type Lib (.tlb file) from a .exe using the command line?

like image 282
Dan Kendall Avatar asked Nov 26 '10 11:11

Dan Kendall


1 Answers

Tlbimp.exe can handle a type library resource inside an EXE just fine. For example:

C:\temp\temp>tlbimp c:\windows\system32\wiaacmgr.exe
Microsoft (R) .NET Framework Type Library to Assembly Converter 3.5.30729.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Type library imported to WIAACMGRLib.dll

Automating this is fairly risky btw. A type library is quite equivalent to an assembly reference. If it changed you want to know about it. Not just because you may well have to modify your interop code and retest it, DLL Hell is knocking on your door as well.

like image 100
Hans Passant Avatar answered Sep 22 '22 14:09

Hans Passant