【问题标题】:C# Return value calling 3rd party com objectC# 返回值调用第 3 方 com 对象
【发布时间】:2017-05-14 03:00:10
【问题描述】:

COM 对象对我来说是全新的领域,我搜索了很多,但都没有运气。我正在调用第 3 方 COM 对象,我可以让它做它应该做的事情,但它总是返回 null,我需要下一步的值。它的示例在 Python 中,它按预期返回。我的代码如下,如何设置才能获取返回值?

Type t = Type.GetTypeFromProgID("3rdParty.Name");

object publisher = Activator.CreateInstance(t);

object[] args = new object[6];

//fill in the args

//It works and does what it is supposed to behind the scenes, 
//but need the int return value.  
//Right now it is always null
int? handle = (int?)t.InvokeMember("DoYourThing", 
                                    BindingFlags.InvokeMethod, 
                                    null, 
                                    publisher, 
                                    args);

【问题讨论】:

  • 你为什么不直接use a COM interop wrapper?它将把整个事情变成一项微不足道的任务。
  • 我不知道它的存在,因为我说过这对我来说是全新的。像魅力一样工作!

标签: c# com


【解决方案1】:

根据Lynn Crumbling 的评论,这就是解决方案。

Best way to access COM objects from C#

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 2014-09-29
    • 2013-10-29
    • 1970-01-01
    • 2010-11-24
    • 2014-03-05
    相关资源
    最近更新 更多