【发布时间】: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?它将把整个事情变成一项微不足道的任务。
-
我不知道它的存在,因为我说过这对我来说是全新的。像魅力一样工作!