本文介绍了在使用COM对象反射调用的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GetLifetimeService InitializeLifetimeService CreateObjRef 的ToString 等于 的GetHashCode 的GetType
GetLifetimeService
InitializeLifetimeService
CreateObjRef
ToString
Equals
GetHashCode
GetType
我有一个COM对象......这是这样创造了一个实例:
I have an instance of a COM object... which is created like this:
Type type = TypeDelegator.GetTypeFromProgID("Broker.Application"); Object application = Activator.CreateInstance(type);当我尝试调用一个方法:
When I try to invoke a method:
type.GetMethod("RefreshAll").Invoke(application, null);
- > type.GetMethod(RefreshAll)返回空。 当我试图让所有方法type.GetMethods(),只有这些方法:
-> type.GetMethod("RefreshAll") returns null. When I try to get all the methods with type.GetMethods(), there is only these methods:
在哪儿RefreshAll方法?我怎么能调用它?
Where is the RefreshAll Method? And how can I invoke it?
推荐答案您不能在COM对象使用GetMethod,你必须使用一个不同的方式:
You can't use GetMethod on COM objects, you have to use a different way:
this.application.GetType().InvokeMember("RefreshAll", BindingFlags.InvokeMethod, null, this.application, null);
我使用这种方式在使用COM所以它应该工作正常为你的老项目。
I am using this way in a old project that uses COM so it should work ok for you.
更多推荐
在使用COM对象反射调用的方法
发布评论