如何访问COM虚函数表,并接取在C#中的TLB(类型库)的项目? [英] How to access COM vtable and acess its entries from TLB(Type Library) in C#?

查看:189
本文介绍了如何访问COM虚函数表,并接取在C#中的TLB(类型库)的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问COM虚函数表具有的这是在C#中在某些特定的接口暴露给外界的功能项。

I need to access COM vtable which have entries of those functions which are exposed to outside world under some specific interface in C#.

我已经访问和遍历封闭在TLB与 LoadTypeLib 的类型,并与的ITypeInfo 播放。

I've accessed and iterate over the types enclosed in the TLB with LoadTypeLib and playing with ITypeInfo.

现在我唯一需要逐一访问一个内部COM接口的虚函数表的方法,并需要通过一种方式来调用它们在运行时的。

Now only thing I need to access one by one those methods inside vtable of COM Interface and need to call them at RUNTIME one by one.

我需要COM虚函数表的地址和它的索引条目(即函数地址)。

I need COM vtable address and its indexed entries (i.e function addresses).

推荐答案

您可以创建从TLB使用TlmImp.exe程序一个C#包装。见如何:生成主互操作程序集使用Tlbimp.exe将了解更多信息

You can create a C# wrapper from the TLB using the TlmImp.exe program. See How to: Generate Primary Interop Assemblies Using Tlbimp.exe for more info.

例如。 TLBIMP LibUtil.tlb /主/keyfile:CompanyA.snk /out:LibUtil.dll

编辑:为了反映意见

由于C#code总是在CLR 运行任何调用非托管的世界将需要进行编组正确。您的选择

Since C# code is always running in the CLR any call to the unmanaged world will need to be marshalled correctly. You have the option of

(一)允许只是做了互操作的生成的包装,或

(a) allowing the generated wrappers of just doing the interop, or

(二)可以优化包装你的自我。

(b) you can optimise the wrappers your self.

(三)其他的事情你可以做的是写在托管C ++来OEN包装,然后通过虚表直接调用。我怀疑这会给你一个非常低的调用开销。

(c) The other thing you can do is to write your oen wrapper in managed c++ and then call through the vtable directly. I suspect this will give you a very low call overhead.

(四)最后的选择是只写一个简单的非托管的C DLL与一个单一的功能和使用的的P / Invoke 将其直接从管理code调用。

(d) The final option is to just write a simple unmanaged c dll with a single function and use P/Invoke to call it directly from the managed code.

这篇关于如何访问COM虚函数表,并接取在C#中的TLB(类型库)的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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