How to Extract TypeLib from a COM exe on Command L

2019-02-17 11:04发布

问题:

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?

回答1:

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.