Author Topic: C# - Create C++ style COM Object using System.Reflection.Type.GetTypeFromProgID  (Read 1414 times)


  • Administrator
  • Full Member
  • *****
  • Posts: 69
In C++, we can use CoCreateInstance with progid or classid to create a COM object on the client.

C# does support similar way of creating COM object with  System.Reflection.Type.GetTypeFromProgID. All you need to do is passing the ProgId. The return value is System.Reflection.Type.

Then you can retrieve the all method information with GetMethods() call that returns MethodInfo[].

Code: (C#)
//Source Code Listing

using System.Reflection;

namespace SFTCSClientConsole
    class Program
        static void Main(string[] args)

                Type mathType = Type.GetTypeFromProgID("SFTComServer.MathControl");

                object mathInstance = Activator.CreateInstance(mathType);

                object[] arguments = new object[3] { 10, 15, 25 };

                object result = mathType.InvokeMember("AddTwoNumbers", BindingFlags.InvokeMethod,
                     null, mathInstance, arguments);

                if(arguments[2] != null)


Additional Information: For server code, refer to the attachment:

« Last Edit: December 01, 2011, 06:07:45 pm by kathir »


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1