How to access COM vtable and acess its entries from TLB(Type Library) in C#?

允我心安 提交于 2019-12-11 18:34:16

问题


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

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

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.

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


回答1:


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.

e.g. tlbimp LibUtil.tlb /primary /keyfile:CompanyA.snk /out:LibUtil.dll

Edit: To reflect comment.

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



来源:https://stackoverflow.com/questions/2818418/how-to-access-com-vtable-and-acess-its-entries-from-tlbtype-library-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!