Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are *.tlb files ever used at runtime?

Tags:

.net

com

I'm working on a product that exposes some .NET API through COM interop. As a part of the build we generate *.tlb files for all such assemblies and deliver them as a part of a separate SDK package. Our customers can install the SDK on top of our product and create applications that use our COM API.

Do we need to ship and register those *.tlb files with the product itself? Is there a situation when *.tlb are required at runtime, when third-party libraries coded against them are executed?

Please explain how it works, if you answer Yes. I seen a lot of comments all over the internet that say that I have to deliver and register them, but I did not find one that clearly explains why it should be done. That made me doubt that it is true.

like image 861
Dennis Avatar asked Jan 09 '13 20:01

Dennis


People also ask

Where are TLB files stored?

Referencing the physical memory addresses, a TLB may reside between the CPU and the CPU cache, between the CPU cache and primary storage memory, or between levels of a multi-level cache.

How do I inspect a TLB file?

Do File > View TypeLib , open your . tlb file. The tool decompiles back to IDL, essentially.

What applications open a TLB file?

applications that open a .tlb file. Microsoft Excel 2010 is one of the many versions of spread sheet tools that were released by Microsoft. This program has built-in tools which includes the ones being used for visualization and analysis which helps its users highlight as well as track the data trends which are deemed important.

Do I need to register a DLL file for TLB project?

So you do not need to registering .Net dll (.tlb project). I hope it will work. Share Improve this answer Follow answered Aug 21 '17 at 15:30 Inder KUMAR SINGHInder KUMAR SINGH 1 Add a comment | Your Answer Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

What is the use of TLB in regasm?

Which uses a type library to find out what the argument types are. The Regasm.exe /tlb option ensures that the interface proxy/stub and type library is registered so the standard marshaller can find the library. When you expose a struct in your public interface.

What is a type library in COM?

Type Library. A type library (.tlb) is a binary file that stores information about a COM or DCOM object's properties and methods in a form that is accessible to other applications at runtime. Using a type library, an application or browser can determine which interfaces an object supports, and invoke an object's interface methods.


1 Answers

Yes, that's possible. Especially in the case of .NET, you should not omit registering the type library because you cannot predict how the client code is going to use your server.

They are not particularly common but there are two cases:

  • When the client code calls your [ComVisible] method and the call crosses an apartment boundary. Apartments are a COM concept that is a bit fuzzy, you have to understand the difference between STA and MTA threads. Keeping it simple: an apartment boundary is typically crossed when the call is made from another thread, from another process or from another machine. COM needs help to figure out how to serialize the arguments of the call into a IPC packet and that requires knowing the type of the arguments. There is no concept of Reflection in COM so it cannot easily be done automatically. A separate DLL is required that implements the proxy and the stub, almost always generated from an IDL file. That's hard to come by in .NET, you almost always use the convenient second way, using the standard marshaller built into Windows. Which uses a type library to find out what the argument types are. The Regasm.exe /tlb option ensures that the interface proxy/stub and type library is registered so the standard marshaller can find the library.

  • When you expose a struct in your public interface. Structs are very troublesome in interop scenarios, they have a layout that's highly dependent on compiler settings. The equivalent .NET property is StructLayout.Pack. Fixed at 8 in .NET but the client code doesn't know that. To access a struct, the client code must use IRecordInfo. Which lets it find out where every field of the struct is located in memory. A type library provides the info that IRecordInfo needs. It is certainly best to avoid structs entirely and very easily done in .NET.

like image 188
Hans Passant Avatar answered Sep 21 '22 09:09

Hans Passant