Reputation: 215
I am trying to call a vb dll (com) from C# using the following code:
Type t = Type.GetTypeFromProgID("DLLName",true);
Object o = Activator.CreateInstance(t);
//object f = Activator.CreateInstance(z);
MethodInfo[] m = t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
However i am not seeing the methods which are exposed in the DLL. I have tried all sorts of BindingFlags combinations such as static, public, nonpublic, instance, etc. Instead I just see these methods exposed. Can anyone help me identify why I am not able to see the methods? Thanks.
Upvotes: 2
Views: 525
Reputation: 12135
The Type which is obtained from GetTypeFromProgID if you specify a COM ProgID is actually always the internal .NET Framework type System.__ComObject
, which is used to implement the COM Interop Runtime Callable Wrapper through which managed code can consume the unmanaged COM object's methods.
The methods of this Type which you can find out about by Reflection, are the managed methods of this managed type, not the unmanaged methods implemented by the wrapped COM object. So the 24 methods listed in your question are the methods of the System.__ComObject
type.
You are limited by the mechanics of COM as to what you can find out about the unmanaged COM methods of a COM object. In general, when using COM you have to know what interface you want to use, and what its requirements are, before you can call any methods on an object. If there is an associated type library, that is where you can get metadata on the methods, but if there isn't, you are trying to do the impossible.
If you could explain why you are trying to call the COM object by discovering MethodInfo objects, rather than using the normal approach of an Interop assembly generated from the COM server's type library, perhaps we could help further.
Upvotes: 2