1

COM objects are brand new territory for me and I've searched quite a bit with no luck. I'm calling a 3rd parties COM object and I can get it to do what it is supposed to, but it always returns null and I need the value for the next step. The sample for it is in Python and it returns as expected. My code is below, how do I set this up so I can get the return value?

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);
Dave_750
  • 1,225
  • 1
  • 13
  • 28
  • 3
    Why don't you just [use a COM interop wrapper](http://stackoverflow.com/questions/635839/best-way-to-access-com-objects-from-c-sharp)? It'll turn this whole thing into a trivial task. – Lynn Crumbling Dec 29 '16 at 18:56
  • I didn't know that existed, as I said this is all new to me. Works like a charm! – Dave_750 Dec 29 '16 at 19:04

1 Answers1

1

Per Lynn Crumbling's comment, this was the solution.

Best way to access COM objects from C#

Community
  • 1
  • 1
Dave_750
  • 1,225
  • 1
  • 13
  • 28