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.

  

posted on 2009-09-17 20:24  listenlisten  阅读(1085)  评论(5编辑  收藏  举报

导航