简体   繁体   English

无法将类型'CommunicatorAPI.MessengerClass'的COM对象转换为接口类型'CommunicatorAPI.IMessengerAdvanced'

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

After following multiple communicatorAPI guides I seem to be stuck. 在遵循了多个communicatorAPI指南之后,我似乎陷入了困境。 In general it boils down to the inability to cast an messenger object as an interface. 通常,可以归结为无法将Messenger对象投射为接口。 Whether it's the messenger obj or the messengerclass obj classes. 无论是Messenger obj还是messengerclass obj类。

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'. 无法将类型“ CommunicatorAPI.MessengerClass”的COM对象转换为接口类型“ 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)). 该操作失败是因为由于以下错误而导致IID为'{DA0635E8-09AF-480C-88B2-AA9FA1D9DB27}'的接口的COM组件上的QueryInterface调用由于以下错误而失败:不支持此类接口(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();" 我还使用“ Messenger msgr = new Messenger();”尝试了上述代码。 With no luck. 没有运气。

Unable to cast COM object of type 'CommunicatorAPI.MessengerClass' to interface type 'CommunicatorAPI.IMessengerAdvanced'. 无法将类型“ CommunicatorAPI.MessengerClass”的COM对象转换为接口类型“ 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)). 该操作失败是因为由于以下错误而导致IID为'{DA0635E8-09AF-480C-88B2-AA9FA1D9DB27}'的接口的COM组件上的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT的异常:0x80004002(E_NOINTERFACE)) 。

I am horribly new to c#, and I have come to a stand still with working with the communicatorAPI. 我对C#感到非常陌生,并且在使用communicatorAPI时一直处于停滞状态。 Btw, the references are added. 顺便说一句,引用添加。 The Embed option is false, and I am stumped. Embed选项为false,这让我很困惑。 Wonder if anyone has figured out a solution. 想知道是否有人找到了解决方案。

Also, I have instantiated the interface with something to effect of: "msgAdv = msgr as IMessengerWndAdvanced;" 另外,我还通过以下方式实例化了接口:“ msgAdv = msgr as IMessengerWndAdvanced;” with no luck. 没有运气。 The variable msgAdv is null every time. 变量msgAdv每次都为null。 I have tried the different examples from M$ and to no avail. 我尝试了从M $到其他示例的尝试,但均无济于事。 Moreover, I have read through the "OCSDK.chm" help file that came with the SDK. 此外,我已经阅读了SDK随附的“ OCSDK.chm”帮助文件。 There isn't a mention of the "Exception from HRESULT: 0x80004002 (E_NOINTERFACE)" error. 没有提到“来自HRESULT的异常:0x80004002(E_NOINTERFACE)”错误。

Help? 救命?

According to this MSDN page , Messenger only implments IMessenger3 and DMessengerEvents, so you cannot cast your Messenger object msgr to IMessengerAdvanced. 根据此MSDN页面Messenger仅实现IMessenger3和DMessengerEvent,因此无法将Messenger对象msgr强制转换为IMessengerAdvanced。

If you need to use IMessengerAdvanced then you need to find a class that implements that interface. 如果需要使用IMessengerAdvanced,则需要找到实现该接口的类。 Otherwise you are stuck with using methods of the IMessenger3 interface. 否则,您将无法使用IMessenger3接口的方法。

In all examples I could find it was Messenger msgr = new Messenger(); 在所有示例中,我都能找到它是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. 但是更重要的是,仅在成功调用msgr.AutoSign()之后才将IMessengerAdvancedIMessengerAdvanced ...这与您的代码有所不同。

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. 由于IMessengerAdvanced只是IMessenger3的一部分,它的IMessenger3取决于服务器端的配置,因此只有在您登录后才能在运行时使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用ExeCOMServer时,无法将类型为“...”的COM对象转换为接口类型“...” - Unable to cast COM object of type '…' to interface type '…' while using an ExeCOMServer InvalidCastException:无法将类型x的COM对象转换为接口类型y - InvalidCastException: Unable to cast COM object of type x to interface type y :'无法将类型为'System .__ ComObject'的COM对象转换为接口类型 - : 'Unable to cast COM object of type 'System.__ComObject' to interface type Crystal 报错 Unable to cast COM object of type 'ReportSourceClass' to interface type 'ISCRReportSource' - Crystal reports error Unable to cast COM object of type 'ReportSourceClass' to interface type 'ISCRReportSource' SAP:无法将“System.__ComObject”类型的 COM 对象转换为接口类型“sapfewse.GuiTextField” - SAP: Unable to cast COM object of type 'System.__ComObject' to interface type 'sapfewse.GuiTextField' 无法将类型'System .__ ComObject'的COM对象转换为IRTDUpdateEvent的接口类型 - Unable to cast COM object of type 'System.__ComObject' to interface type for IRTDUpdateEvent 无法将COM对象强制转换为类类型 - Unable to cast COM Object to class type 无法转换类型异常的COM对象 - Unable to cast COM object of type exception 在C#中加载COM对象抛出异常“无法将类型为'System .__ ComObject'的COM对象转换为接口类型...”,但C ++或VB没有 - Loading COM object in C# throws exception “Unable to cast COM object of type 'System.__ComObject' to interface type …”, but C++ or VB not 无法将COM对象强制转换为接口类型'WUApiLib.UpdateSession c# - Unable to cast COM object to interface type 'WUApiLib.UpdateSession c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM