views:

63

answers:

1

Hello,

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

Regards Usman

A: 

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.

Preet Sangha
This will generate more code WHICH I DONT NEED? I dont need code to work with. I NEED TO CALL COM UNMANAGED EXPOSED METHODS AT RUNTIME IN .NET. This requires to pull out and extract all information(e.g function and their addresses at runtime). I've got all function names and their arguments(parameters) by parsing type library(tlb).Now I need to know the EXPOSED FUNCTION ADDRESS So that I can call that EXPOSED METHOD OF CERTAIN INTERFACE AT RUNTIME.
Usman
At RUNTIME (knowing names and params of methods), in .NET except address wot else required to call at RUNTIME?Do we need to write marshaller in .NET for every function call? Wot about Dispatch.Invoke? Will it help?
Usman
The .net code runns in managed space. You need to marshall every call out of there. You cannot just issue a jmp. I suggest that less uppercase will make it easier to ready your comments.
Preet Sangha