Unable to cast COM object of type 'CommunicatorAPI.MessengerClass' to interface type 'CommunicatorAPI.IMessengerAdvanced'

StackOverflow https://stackoverflow.com/questions/7263693

  •  17-01-2021
  •  | 
  •  

Question

After following multiple communicatorAPI guides I seem to be stuck. In general it boils down to the inability to cast an messenger object as an interface. Whether it's the messenger obj or the messengerclass obj classes.

Upon attempting to cast the object, I recieve the following exception.

Unable to cast COM object of type 'CommunicatorAPI.MessengerClass' to interface type 'CommunicatorAPI.IMessengerAdvanced'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DA0635E8-09AF-480C-88B2-AA9FA1D9DB27}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

This is an example of the code I am trying to run, stripped down to just what throws the exception.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunicatorAPI;

namespace OCA
{
    class OCA_main
    {
        static void Main(string[] args)
        {
            OCA m = new OCA();
            m.subscribe();
            m.startconvo("emailaddress");

        }
    }

    class OCA
    {
        MessengerClass msgr = new MessengerClass();
       // Messenger msgr = new Messenger(); //Tried this too... :(

        IMessengerAdvanced msgrAdv;


        public void subscribe()
        {
            msgr.OnIMWindowCreated += new DMessengerEvents_OnIMWindowCreatedEventHandler(msgr_OnIMWindowCreated);
        }

        public void unsubscribe()
        {
            msgr.OnIMWindowCreated -=new DMessengerEvents_OnIMWindowCreatedEventHandler(msgr_OnIMWindowCreated);
        }

        void msgr_OnIMWindowCreated(object pIMWindow)
        {
            try
            {

                IMessengerAdvanced msgrAdv = (IMessengerAdvanced)msgr;
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex.Message);
            }

            throw new NotImplementedException();
            //... stuff
        }

        public void startconvo(string users)
        {
            try
            {

                IMessengerAdvanced msgrAdv = (IMessengerAdvanced)msgr;
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex.Message);
            }
        }

    }
}

I have also tried the above code using "Messenger msgr = new Messenger();" With no luck.

Unable to cast COM object of type 'CommunicatorAPI.MessengerClass' to interface type 'CommunicatorAPI.IMessengerAdvanced'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DA0635E8-09AF-480C-88B2-AA9FA1D9DB27}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I am horribly new to c#, and I have come to a stand still with working with the communicatorAPI. Btw, the references are added. The Embed option is false, and I am stumped. Wonder if anyone has figured out a solution.

Also, I have instantiated the interface with something to effect of: "msgAdv = msgr as IMessengerWndAdvanced;" with no luck. The variable msgAdv is null every time. I have tried the different examples from M$ and to no avail. Moreover, I have read through the "OCSDK.chm" help file that came with the SDK. There isn't a mention of the "Exception from HRESULT: 0x80004002 (E_NOINTERFACE)" error.

Help?

Was it helpful?

Solution

In all examples I could find it was Messenger msgr = new Messenger(); BUT even more important the cast to IMessengerAdvanced only occurs AFTER msgr.AutoSign() is called successfully... which is a difference to your code.

Since IMessengerAdvanced is just some addition to IMessenger3 and the availibility of it is something depending on server-side configuration it only could become available at runtime AFTER you are signed in.

OTHER TIPS

According to this MSDN page, Messenger only implments IMessenger3 and DMessengerEvents, so you cannot cast your Messenger object msgr to IMessengerAdvanced.

If you need to use IMessengerAdvanced then you need to find a class that implements that interface. Otherwise you are stuck with using methods of the IMessenger3 interface.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top