1

我有以下调用 COM 接口 api (MS Mobile API) 的代码片段

try
{
    MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
    IMbnInterfaceManager infMgr = (IMbnInterfaceManager)mbnInfMgr;

    IMbnInterface[] interfaces = (IMbnInterface[])infMgr.GetInterfaces();
    ///
    /// NOTE: Will throw exception here if no Adapter Present - "Service not Started"
    ///
    foreach (IMbnInterface mobileInterface in interfaces)
    {
        MBN_INTERFACE_CAPS caps = mobileInterface.GetInterfaceCapability();
        MBN_READY_STATE readyState = mobileInterface.GetReadyState();
        IMbnRadio radio = (IMbnRadio)mobileInterface;

        MBN_PROVIDER provider = mobileInterface.GetHomeProvider();
        ///
        /// NOTE: Will throw exception here if no SIM Present.
        ///

COM 异常处理如下

///
/// Handle COM Exceptions 
///
catch (System.Runtime.InteropServices.COMException ex)
{
    switch ((uint)ex.ErrorCode)
    {
        case 0x8054820A:
             // ...
             break;

        case 0x80070490:
             // ...
             break;

             default:
             string str = "COM: " + ex.Message;
             break;
    }
}

我遇到的问题是,并非所有我认为的异常都是致命的,就像在“无 SIM”异常中一样,我仍然需要访问已创建的 COM 接口组件,但异常会终止所有这些实例。

我应该怎么做,还是我必须再次通过构造程序?

感谢您的任何建议

莎拉 T

4

0 回答 0