0

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?

4

2 回答 2

1

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.

于 2011-08-31T21:41:53.957 回答
0

在所有示例中,我发现它Messenger msgr = new Messenger();更重要的是仅在成功调用IMessengerAdvanced之后才发生强制转换msgr.AutoSign()......这与您的代码不同。

由于IMessengerAdvanced只是一些补充IMessenger3,它的可用性取决于服务器端配置,它只能在您登录后在运行时可用。

于 2011-08-31T23:35:55.980 回答