【问题标题】:Mobile Broadband C# interface to manage Profiles用于管理配置文件的移动宽带 C# 接口
【发布时间】:2013-06-11 12:01:36
【问题描述】:

我正在尝试使用移动宽带 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))。

微软列出的调用如下:

IMbnConnectionProfile Interface Method C# Signature

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

看起来我需要指定接口,但似乎不知道如何执行此操作。

谁能告诉我怎么做?

【问题讨论】:

    标签: c# mobile com broadband


    【解决方案1】:

    通过调用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);
    

    【讨论】:

    • 谢谢雅各布,我现在将尝试使用您的解决方案 - 非常感谢您抽出时间来回答我的问题。
    • 我现在已经能够从每个接口读取配置文件到 xml 文档,但我无法编辑/修改,抛出异常,下面的代码没有详细信息。
    • XDocument xdoc = XDocument.Parse(profArr[0].GetProfileXmlData()); xdoc.Add(new XComment("系统修改"));你知道为什么会这样吗?谢谢
    猜你喜欢
    • 2012-04-15
    • 2015-05-05
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    • 2016-10-28
    相关资源
    最近更新 更多