C#返回值调用第三方com对象

时间:2016-12-29 18:51:00

标签: c# com

COM对象对我来说是一个全新的领域,我搜索了很多而没有运气。我正在调用第三方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);

1 个答案:

答案 0 :(得分:1)

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

Best way to access COM objects from C#