Invoking method or subscribing to an event of a COM object in C#

0

I am newbie in COM. I am having a trouble on creating a plugin for an own software that would intercept traffic on a third party software by the clsid:

All information by the third party owners -->

*clsid: 0BBB797E-D6A8-40F9-B5D1-8E72F4729A03

*event to receive data - OnRecvData(NetworkData) //NetworkData type of string

*event to send data - OnSendData(NetworkData) //NetworkData type of string

I have referenced Invoke method using Reflection on COM Object and tried to get the methods, events, properties that the created instance contains.

Here is the code I have used ->

class Program
{
    private const string WORD_CLSID = "{0BBB797E-D6A8-40F9-B5D1-8E72F4729A03}";

    public static void Main()
    {
        try
        {
            Type comType = Type.GetTypeFromCLSID(new Guid(WORD_CLSID));

            var instance = Activator.CreateInstance(comType);

            Console.WriteLine("//////////////////");

            Console.WriteLine("Created an instance of: " + comType.Name + "-->\nCLSID = " + WORD_CLSID);

            var invokedData = comType.InvokeMember("NetworkData",
                                                    BindingFlags.DeclaredOnly |
                                                    BindingFlags.Public | BindingFlags.NonPublic |
                                                    BindingFlags.Instance | BindingFlags.InvokeMethod, null, instance, null);


            Console.WriteLine("NetworkData ->" + invokedData);

            Console.WriteLine("\nEVENTS ----");

            var comEvents = comType.GetEvents();

            foreach (var comEvent in comEvents)
                Console.WriteLine(comEvent);

            if (comEvents.Count() == 0)
                Console.WriteLine("0");

            var comMethods = comType.GetMethods();

            Console.WriteLine("\nMETHODS --");

            foreach (var comMethod in comMethods)
            {
                var methodDetails = string.Format("{0} {1}({2})", comMethod.ReturnParameter, comMethod.Name,
                                                    string.Join(",", comMethod.GetParameters().Select(p => p.ParameterType.Name)));

                Console.WriteLine("\t" + methodDetails);
            }

            var comProperties = instance.GetType().GetProperties();

            Console.WriteLine("\nPROPERTIES----");

            foreach (var comProperty in comProperties)
                Console.WriteLine(comProperty);

            if (comProperties.Count() == 0)
                Console.WriteLine(0);

            Console.WriteLine("\n--------------------------OVER");

        }
        catch (COMException ex)
        {
            Console.WriteLine("Unable to instantiate object. MESSAGE: " + ex.Message);
        }

        Console.Read();
    }
}

and I get error of type: HRESULT 0x80020006 Unknown name.

How can I resolve this type of problem?

c#-4.0
com
asked on Stack Overflow Mar 25, 2019 by Kurban • edited Mar 25, 2019 by Robert Harvey

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0