在使用COM对象反射调用的方法

编程入门 行业动态 更新时间:2024-10-27 19:25:32
本文介绍了在使用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:

  • GetLifetimeService
  • InitializeLifetimeService
  • CreateObjRef
  • 的ToString
  • 等于
  • 的GetHashCode
  • 的GetType
  • GetLifetimeService
  • InitializeLifetimeService
  • CreateObjRef
  • ToString
  • Equals
  • GetHashCode
  • 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对象反射调用的方法

    本文发布于:2023-11-17 03:45:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1608703.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:反射   对象   方法

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!