以下多個communicatorAPI指南後,我似乎被卡住了。總的來說,它歸結爲無法將信使對象作爲接口。無論是信使obj還是信使類obj類。無法將類型爲'CommunicatorAPI.MessengerClass'的COM對象轉換爲接口類型爲'CommunicatorAPI.IMessengerAdvanced'
試圖轉換對象時,我收到以下異常。
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)).
這是我試圖運行的代碼的一個例子,剝離到只是拋出異常。
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);
}
}
}
}
我也嘗試了上述代碼,使用「Messenger msgr = new Messenger();」沒有運氣。
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)).
我對c#非常陌生,而且我已經和CommunatorAPI一起工作了。順便說一句,參考文獻被添加。 Embed選項是錯誤的,我很難過。不知道有沒有人找出解決方案。
此外,我已經實例化了一些效果如下的接口:「msgAdv = msgr as IMessengerWndAdvanced;」 沒有運氣。變量msgAdv每次都是空的。我嘗試了M $的不同例子,但無濟於事。此外,我已閱讀SDK附帶的「OCSDK.chm」幫助文件。沒有提及「HRESULT異常:0x80004002(E_NOINTERFACE)」錯誤。
幫助?
在我所有的嘗試,我已經簽署因此,msgr.SignIn(blah blah)或msgr.AutoSignIn()不是必需的。其實,再次這樣做,掛斷了溝通。雖然謝謝! :) – embeddednerd
哦,我已經嘗試了MessengerClass msgr = new MessengerClass();作爲Messenger msgr =新的Messenger()引發了類似的異常。我相信在http://msdn.microsoft.com/en-us/library/bb787245(v=office.12).aspx的底部有人建議MessengerClass是正確的類。 – embeddednerd
這意味着你的服務器配置的方式不提供必要的接口......它不是你的代碼,但導致「IMessengerAdvanced」不可用的服務器配置我認爲 – Yahia