0

我正在尝试使用移动宽带 API 的 C# 接口。下面的代码编译并智能感知显示所有的 COM 方法,但代码没有正确执行。

MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
IMbnConnectionProfile conProfile = (IMbnConnectionProfile)mbnInfMgr;

string xmlBuff = conProfile.GetProfileXmlData();

产生以下错误:

无法将“System.__ComObject”类型的 COM 对象转换为 interfacetype
'MbnApi.IMbnConnectionProfile'。
此操作失败,因为 COM 组件上的 QueryInterface 调用
对于 IID 为“{DCBBBAB6-2010-4BBB-AAEE-338E368AF6FA}”的接口失败
由于以下错误:
不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE))。

Microsoft 列出的调用如下:

IMbnConnectionProfile Interface Method C# Signature

Delete              public void Delete();
GetProfileXmlData   public string GetProfileXmlData();
UpdateProfile       public void UpdateProfile( string strProfile);

看起来好像我需要指定接口,但似乎无法找到如何执行此操作。

谁能告诉我如何做到这一点?

4

1 回答 1

0

通过调用IMbnInterfaceManager::GetInterfaceIMbnInterfaceManager::GetInterfaces方法。

例如

MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
IMbnInterfaceManager infManager = (IMbnInterfaceManager)mbnInfMgr;

//obtain the IMbnInterface passing interfaceID
string interfaceID = “{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}”;

IMbnInterface mbnInterface= infMgr.GetInterface(interfaceID);

MbnConnectionProfileManager mbnProfMgr = new MbnConnectionProfileManager();
IMbnConnectionProfileManager profileManager = 
                                  (IMbnConnectionProfileManager)mbnProfMgr;

IMbnConnectionProfile[] profArr = 
(IMbnConnectionProfile[])profileManager.GetConnectionProfiles(mbnInterface);
于 2013-06-11T04:01:36.077 回答