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?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Kurban
  • 1
  • What line throws the exception? And what output do you get from the `Console.WriteLine` calls before the exception occurs? – Michael Gunter Mar 25 '19 at 16:43
  • @MichaelGunter - The line where **InvokeMember** called, it throws an exception with an Unknown name, at line **Console.WriteLine("Created an instance...** i get the name as **__ComObject** so when i just comment Invoke line out, i just see that i have the same methods like here -> [https://stackoverflow.com/questions/2773022/invoke-method-using-reflection-on-com-object] 0 events, 0 properties, only those methods – Kurban Mar 26 '19 at 08:06

0 Answers0