为* .TLB以往任何时候都在运行时使用的文件? [英] Are *.tlb files ever used at runtime?

查看:104
本文介绍了为* .TLB以往任何时候都在运行时使用的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,公开通过COM互操作的一些.NET API的产品。作为构建的一部分,我们为所有这样的组件* .TLB文件,并提供它们作为一个单独的SDK软件包的一部分。我们的客户可以在我们的产品上安装SDK和创建使用我们的COM API的应用程序。

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.

我们需要船舶和注册与产品本身的* .TLB文件?有没有在* .TLB需要在运行时的情况,当对他们的第三方库codeD执行?

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.

推荐答案

是的,这是可能的。尤其是在.NET的情况下,你不应该忽略注册类型库,因为你不能predict如何在客户端code会使用你的服务器。

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:

  • 在客户端code调用你的[标记有ComVisible特性]方法和呼叫跨越公寓的边界。公寓是COM的概念,是一个有点模糊,你必须了解STA和MTA线程之间的差异。保持简单:一个公寓的边界通常跨越通话时从另一个线程所做的,从另一个进程或从另一台机器。 COM需要帮助找出如何调用的参数序列化到IPC数据包,并且需要知道的参数的类型。有反思在COM没有概念,因此它不能很容易地自动完成。一个单独的DLL需要实现代理和存根,几乎都是从IDL文件生成的。这很难在.NET中来的,你几乎总是使用便捷的第二种方式,利用内置于Windows的标准编组。它采用了类型库,找出参数类型。该Regasm.exe / TLB选项确保接口的代理/存根和类型库登记,以便标准编组可以找到库。

  • 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.

当你暴露在公众界面结构。结构是很麻烦的互操作场景,他们有一个布局的高度依赖于编译器设置。等效.NET属性是StructLayout.Pack。固定为8 .NET,但客户端code不知道。要访问一个结构,客户端code必须使用IRecordInfo。它可以让它找出了结构的各个领域位于内存中。 A型库提供了IRecordInfo需要的信息。这当然是最好的,以避免结构完全,很容易在.NET中完成的。

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.

这篇关于为* .TLB以往任何时候都在运行时使用的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆