如何访问COM vtable并从C#中的TLB(类型库)获取它的条目? [英] How to access COM vtable and acess its entries from TLB(Type Library) in C#?

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

问题描述

我需要访问COM vtable,它们具有在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接口的vtable中的一个方法,并需要在RUNTIME逐个调用它们。

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 vtable地址及其索引条目(即函数地址)。

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

推荐答案

可以使用TlmImp从TLB创建C#包装器。 exe程序。请参见如何使用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 / primary /keyfile:CompanyA.snk /out:LibUtil.dll

编辑:

由于C#代码总是在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)允许生成的只是执行interop的包装器,或

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

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

(b) you can optimise the wrappers your self.

(c)你可以做的另一件事是在托管c ++中写你的oen包装,然后直接通过vtable调用。我怀疑这会给你一个非常低的通话开销。

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

(d)最后一个选项是用一个函数写一个简单的非托管c dll,并使用 P / Invoke 直接从托管代码调用它。

(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 vtable并从C#中的TLB(类型库)获取它的条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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