函数: void SipRegister(UserConfig* conf,void (CALLBACK* SipEvent)(int iLineNumber, int  iEventType, WPARAM Param, LPARAM lParam, void* pInstance), void* pAppInstance);typedef struct _user_configure
{
SipSupportCodec SupportCodec;
SipUserConfig SipConfig;
}UserConfig;typedef struct _support_codec
{
int iSupportCodecNumbers;
CodecInfo CodecInfos[16];//
}SipSupportCodec;typedef struct _codec_info
{
int iPayLoadType; // 编码的PayLoadType
int iSampleRate; //采样率
char szName[32];// 名字,也就是MIME
}CodecInfo;typedef struct _user_sip_configure
{
char szPhoneNumber[CONF_ITEM_LEN]; // 号码
char szUserName[CONF_ITEM_LEN]; //用户名,可以和号码相同
char szPassword[CONF_ITEM_LEN];//密码
char szDomain[CONF_ITEM_LEN];//Domain,可以和Proxy相同
char szProxy[CONF_ITEM_LEN];//注册的服务器地址
char szStun[CONF_ITEM_LEN];// stun服务器地址
int iSipPort; //本地的 Sip使用的端口
int iRTPProt;//本地的 RTP 使用的端口
bool bUseStun; //是否使用stun
bool bAutoRegister;// 是否自动注册,建议值设为1
}SipUserConfig;我自己写的老是提示参数错误 ,我就不贴了,请各位帮帮忙

解决方案 »

  1.   

    //----------------声明两个委托,相当于VC里面的回调函数------------------ 
      public delegate void OnSmgMsg(int iLineNumber, int iEventType, IntPtr wParam, IntPtr lParam, IntPtr pInstance); 
    //--------------------------------------------------------------------- 
    UserConfig pUserConfig; 
            public MainWindow()
            {
                InitializeComponent();
                pUserConfig = new UserConfig();
            }
            [DllImport("ppsip.dll")]       
            public static extern void SipRegister(ref UserConfig conf,
        OnSmgMsg pf, IntPtr pAppInstance);
            private void button1_Click(object sender, RoutedEventArgs e)
            {
               
                    InitCodec();
                    OnSmgMsg pt = new OnSmgMsg(callBack);
                    UsersipConfig pUserSipConfig = new UsersipConfig();
                    pUserSipConfig.szPhoneNumber = "889017";
                    pUserSipConfig.szPassword = "123456";
                    pUserSipConfig.szUserName = "889017";
                    pUserSipConfig.szDomain = "10.19.185.62";
                    pUserSipConfig.szProxy = "10.19.185.62:5060";
                    pUserSipConfig.iSipPort = 10060;
                    pUserSipConfig.iRTPProt = 10066;
                    pUserSipConfig.bUseStun = false;
                    pUserSipConfig.szStun = "";
                    pUserSipConfig.bAutoRegister = true;
                    pUserConfig.usersipconfig = pUserSipConfig;
                    IntPtr a = new IntPtr(2121);
                    SipRegister(ref pUserConfig, pt, a);      
           }
            private void InitCodec()
            {
            
              SupportCodec supportcodec = new SupportCodec();
               supportcodec.iSupportCodecNumbers = 3;
                CodecInfo[] pCodecInfo = new CodecInfo[1];
                pCodecInfo[0].szName = "G729";
                pCodecInfo[0].iSampleRate = 8000;
                pCodecInfo[0].iPayLoadType = 18;
               supportcodec.CodecInfos = pCodecInfo;
               pUserConfig.supportcodec = supportcodec;
                        }
            public static void callBack(int iLineNumber, int iEventType, IntPtr wParam, IntPtr lParam, IntPtr pInstance)
            {
                int S = iLineNumber + iEventType;
            }
        }
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        public struct UserConfig
        {
            public SupportCodec supportcodec;
            public UsersipConfig usersipconfig;
        }
         
        [StructLayout(LayoutKind.Sequential,Pack=4)]
      public struct SupportCodec
      {
          public  int iSupportCodecNumbers;      //[MarshalAs(UnmanagedType.LPStruct, SizeConst = 17)]     
         public  CodecInfo[] CodecInfos;
               
      }
        [StructLayout(LayoutKind.Sequential,Pack=4)]
        public struct  CodecInfo
        {
          public  int iPayLoadType; // 编码的PayLoadType
    public  int iSampleRate; //采样率
              [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string szName;// 名字,也就是MIME    }
        [StructLayout(LayoutKind.Sequential, Pack = 4)]
        public struct UsersipConfig
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public string szPhoneNumber; // 号码
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public string szUserName; //用户名,可以和号码相同
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public string szPassword;//密码
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
            public string szDomain;//Domain,可以和Proxy相同
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)]
            public string szProxy;//注册的服务器地址
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 17)]
            public string szStun;// stun服务器地址
            public int iSipPort; //本地的 Sip使用的端口
            public int iRTPProt;//本地的 RTP 使用的端口
            public bool bUseStun; //是否使用stun
            public bool bAutoRegister;// 是否自动注册,建议值设为1    }
      

  2.   

      [DllImport("xxxx.dll", CallingConvention = CallingConvention.Cdecl)]
    加一句 CallingConvention = CallingConvention.Cdecl 就行了,
    一般API调用,如果参数等没有错,但运行还是有错,就可能是API的外部函数的函数堆栈调用方式跟你自己定义不同还是群里的高手多 ,