zoukankan      html  css  js  c++  java
  • P/Invoke调用SipEnumIM枚举SIP失败?


    通过.NET CF本身提供的方法枚举设备中的所有SIP可以方便的完成这个问题。如下:
            // 定义一个InputPanel 
            private InputPanel m_inputPanel = new InputPanel();
            
            // 枚举SIP
            foreach (InputMethod method in m_inputPanel.InputMethods)
            {
                
    this.listBox.Items.Add(method.Name);
            }

    通过上面的方式枚举设备所有SIP后,就可以选择自己需要的SIP了
            private void SetNewSIP(string sipName)
            {
                
    foreach (InputMethod method in m_inputPanel.InputMethods)
                {
                    
    if (sipName.Equals(method.Name))
                    {
                        m_inputPanel.CurrentInputMethod 
    = method;
                        
    break;
                    }
                }
            }
     




    ASK:
        我想P/Invoke系统API来实现.NET CF为我们实现的枚举功能,如下代码,但是总是返回0,也就是没有枚举到,请问,是我的结构体参数设置错误还是其他呢?
        public class SIPManager
        {
            
    public delegate int IMENUMPROC(ref IMENUMINFO IMinfo);
            [DllImport(
    "coredll.dll")]
            
    public static extern int SipEnumIM(IMENUMPROC EnumIMProc);
            
    private List<IMENUMINFO> SIPs = new List<IMENUMINFO>();

            
    public int SipEnumIMProc(ref IMENUMINFO IMinfo)
            {
                SIPs.Add(IMinfo);
                
    return 1;
            }

            
    public List<IMENUMINFO> GetSIPs()
            {
                
    int imcount = SipEnumIM(SipEnumIMProc);
                
    return SIPs;
            }

            
    public class IMENUMINFO
            {
                
    public StringBuilder szName;
                
    public Guid clsid;
                
                
    public IMENUMINFO()
                {
                    szName 
    = new StringBuilder();
                    clsid 
    = new Guid();
                }
            }
        }


        
    // 按照下面方式调用
        SIPManager sipmgr = new SIPManager();
        List
    <SIPManager.IMENUMINFO> list = new List<SIPManager.IMENUMINFO>();
        list 
    = sipmgr.GetSIPs();

        
    // 但是每次跟踪进GetSIPs之后,里面imcount返回值总为0,也就是表示失败







     

    --------------------------------------------------

    李森 – listen
    E-mail:  lisencool@gmail.com

    声明:
    这里集中了在WinCEWindows Mobile开发中的一些基本常识。我很乐意和大家分享,也希望大家提出意见,并给我投稿,我会第一时间替您发表并署上您的大名!

    Announce:
    Here collects general knowledge on WinCE and Windows mobile. I 'm very glad to share them with all friends, and also hope you can share your problems and opinions and contribute articles to me to share with others. I'll publish your articles and sign your name at the first time.

      
  • 相关阅读:
    【HDU 4305】Lightning(生成树计数)
    【HDU 1150】Machine Schedule(二分图匹配)
    【HDU 2063】过山车(二分图匹配)
    透过Nim游戏浅谈博弈
    [SCOI2010]字符串
    [SCOI2010]传送带[三分]
    [SCOI2010]序列操作[分块or线段树]
    HDU 5306 Gorgeous Sequence[线段树区间最值操作]
    1455: 罗马游戏[左偏树or可并堆]
    Codevs 5914 [SXOI2016]最大值
  • 原文地址:https://www.cnblogs.com/Lisen/p/1568754.html
Copyright © 2011-2022 走看看