C# 从C调用vbdll的方法#
我试图使用以下代码从C#调用vb dll(com):C# 从C调用vbdll的方法#,c#,com,com-interop,C#,Com,Com Interop,我试图使用以下代码从C#调用vb dll(com): Type t = Type.GetTypeFromProgID("DLLName",true); Object o = Activator.CreateInstance(t); //object f = Activator.CreateInstance(z); MethodInfo[] m = t.GetMethods(BindingFlags.Public | BindingFlags.No
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);
但是,我没有看到DLL中公开的方法。我尝试了各种BindingFlags组合,比如static、public、nonpublic、instance等。相反,我只看到这些方法公开。有人能帮我确定为什么我看不到这些方法吗?谢谢
- [0]{IntPtr GetIUnknown(Boolean ByRef)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [1] {System.Object GetData(System.Object)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [2] {Boolean SetData(System.Object,System.Object)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [3] {Void ReleaseAllData()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [4] {System.Object GetEventProvider(System.Type)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [5] {Int32 ReleaseSelf()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [6] {Void FinalReleaseSelf()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [7] {System.Object CreateEventProvider(System.Type)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [8] {IntPtr GetComIUnknown(布尔)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [9] {Boolean IsInstanceOfType(System.Type)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [10] {System.Object InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [11] {System.MarshallByRefObject MemberwiseClone(布尔)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [12] {System.Runtime.Remoting.ServerIdentity}RaceSetServerIdentity(System.Runtime.Remoting.ServerIdentity)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [13] {Void{uuuu ResetServerIdentity()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [14] {System.Object GetLifetimeService()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [15] {System.Object InitializeLifetimeService()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [16] {System.Runtime.Remoting.ObjRef CreateObjRef(System.Type)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [17] {Boolean cancastoxmltype(System.String,System.String)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [18] {System.String ToString()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [19] {Boolean Equals(System.Object)}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [20] {Int32 GetHashCode()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [21]{System.Type GetType()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [22]{Void Finalize()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
- [23]{System.Object MemberwiseClone()}System.Reflection.MethodInfo{System.Reflection.RuntimeMethodInfo}
System.\uu ComObject
,用于实现COM互操作运行时可调用包装器,托管代码可通过该包装器使用非托管COM对象的方法
您可以通过反射找到的这种类型的方法是这种托管类型的托管方法,而不是由包装的COM对象实现的非托管方法。因此,您问题中列出的24种方法是系统的方法
在COM对象的非托管COM方法方面,您受到COM机制的限制。通常,在使用COM时,在调用对象上的任何方法之前,必须知道要使用的接口及其要求。如果存在关联的类型库,则可以从中获取方法的元数据,但如果没有,则是在尝试做不可能的事情
如果您可以解释为什么您试图通过发现MethodInfo对象来调用COM对象,而不是使用从COM服务器的类型库生成的互操作程序集的常规方法,那么我们可能会进一步提供帮助