在使用COM对象反射调用的方法 [英] Invoke method using Reflection on COM Object

查看:133
本文介绍了在使用COM对象反射调用的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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:


  1. GetLifetimeService

  2. InitializeLifetimeService

  3. CreateObjRef

  4. 的ToString

  5. 等于

  6. 的GetHashCode

  7. 的GetType

  1. GetLifetimeService
  2. InitializeLifetimeService
  3. CreateObjRef
  4. ToString
  5. Equals
  6. GetHashCode
  7. GetType

在哪儿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对象反射调用的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆