How to Extract TypeLib from a COM exe on Command Line
Asked Answered
P

1

5

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?

Pamphlet answered 26/11, 2010 at 11:18 Comment(0)
I
9

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.

Implement answered 26/11, 2010 at 16:21 Comment(1)
Thanks Hans. The COM exe changes fairly frequently and a number of our projects target .net 2. Including interop dlls in vs2010 against .net 2 requires some messing about so I'm investigating some ways forward. As our projects target a single version of the COM library, the risks of DLL Hell are low, but I'm grateful to you for highlighting the risk. Cheers,Pamphlet

© 2022 - 2024 — McMap. All rights reserved.