1. 程式人生 > >即時通訊開發平臺的部分C#原始碼

即時通訊開發平臺的部分C#原始碼

using System;   
using System.Text;   
using System.Runtime.InteropServices;   
  
namespace Platform   
{   
    /********************************************************************************  
    * ** AnyChat Platform Core SDK  
    * *********************************************************************************/  
    public class AnyChatCoreSDK   
    {  
        #region AnyChat Platform Core SDK 常量定義   
        // 核心引數定義,API:BRAC_SetSDKOption、BRAC_GetSDKOption 傳入引數   
        public const int BRAC_SO_AUDIO_VADCTRL          =   1;  // 音訊靜音檢測控制(引數為:int型:1開啟,0關閉)   
        public const int BRAC_SO_AUDIO_NSCTRL           =   2;  // 音訊噪音抑制控制(引數為:int型:1開啟,0關閉)   
        public const int BRAC_SO_AUDIO_ECHOCTRL         =   3;  // 音訊迴音消除控制(引數為:int型:1開啟,0關閉)   
        public const int BRAC_SO_AUDIO_AGCCTRL          =   4;  // 音訊自動增益控制(引數為:int型:1開啟,0關閉)   
        public const int BRAC_SO_AUDIO_CPATUREMODE      =   5;  // 音訊採集模式設定(引數為:int型:0 發言模式,1 放歌模式,2 卡拉OK模式,3 線路輸入模式)   
        public const int BRAC_SO_AUDIO_MICBOOST         =   6;  // 音訊採集Mic增強控制(引數為:int型:0 取消,1 選中,2 裝置不存在[查詢時返回值])   
        public const int BRAC_SO_RECORD_VIDEOBR         =   10; // 錄影視訊位元速率設定(引數為:int型,單位:bps)   
        public const int BRAC_SO_RECORD_AUDIOBR         =   11; // 錄影音訊位元速率設定(引數為:int型,單位:bps)   
        public const int BRAC_SO_RECORD_TMPDIR          =   12; // 錄影檔案臨時目錄設定(引數為字串PCHAR型別,必須是完整的絕對路徑)   
        public const int BRAC_SO_SNAPSHOT_TMPDIR        =   13; // 快照檔案臨時目錄設定(引數為字串PCHAR型別,必須是完整的絕對路徑)   
        public const int BRAC_SO_CORESDK_TMPDIR         =   14; // 設定AnyChat Core SDK臨時目錄(引數為字串PCHAR型別,必須是完整的絕對路徑)   
        public const int BRAC_SO_CORESDK_PATH           =   20; // 設定AnyChat Core SDK相關元件路徑(引數為字串PCHAR型別,必須是完整的絕對路徑)   
        public const int BRAC_SO_LOCALVIDEO_BITRATECTRL =   30; // 本地視訊編碼位元速率設定(引數為int型,單位bps,同伺服器配置:VideoBitrate)   
        public const int BRAC_SO_LOCALVIDEO_QUALITYCTRL =   31; // 本地視訊編碼質量因子控制(引數為int型,同伺服器配置:VideoQuality)   
        public const int BRAC_SO_LOCALVIDEO_GOPCTRL     =   32; // 本地視訊編碼關鍵幀間隔控制(引數為int型,同伺服器配置:VideoGOPSize)   
        public const int BRAC_SO_LOCALVIDEO_FPSCTRL     =   33; // 本地視訊編碼幀率控制(引數為int型,同伺服器配置:VideoFps)   
        public const int BRAC_SO_LOCALVIDEO_PRESETCTRL  =   34; // 本地視訊編碼預設引數控制(引數為int型,1-5)   
        public const int BRAC_SO_LOCALVIDEO_APPLYPARAM  =   35; // 應用本地視訊編碼引數,使得前述修改即時生效(引數為int型:1 使用新引數,0 使用預設引數)   
        public const int BRAC_SO_LOCALVIDEO_VIDEOSIZEPOLITIC=36;// 本地視訊採集分辯率控制策略(引數為int型,0 自動向下逐級匹配[預設];1 使用採集裝置預設分辯率),當配置的分辯率不被採集裝置支援時有效   
        public const int BRAC_SO_LOCALVIDEO_DEINTERLACE =   37; // 本地視訊反交織引數控制(引數為int型: 0 不進行反交織處理[預設];1 反交織處理),當輸入視訊源是隔行掃描源(如電視訊號)時通過反交織處理可以提高畫面質量   
        public const int BRAC_SO_NETWORK_P2PPOLITIC     =   40; // 本地網路P2P策略控制(引數為:int型:0 禁止本地P2P,1 伺服器控制P2P[預設],2 上層應用控制P2P連線,3 按需建立P2P連線)   
        public const int BRAC_SO_NETWORK_P2PCONNECT     =   41; // 嘗試與指定使用者建立P2P連線(引數為int型,表示目標使用者ID),連線建立成功後,會通過訊息反饋給上層應用,P2P控制策略=2時有效   
        public const int BRAC_SO_NETWORK_P2PBREAK       =   42; // 斷開與指定使用者的P2P連線(引數為int型,表示目標使用者ID)[暫不支援,保留]   
  
        // 使用者狀態標誌定義,API:BRAC_QueryUserState 傳入引數   
        public const int BRAC_USERSTATE_CAMERA          =   1;  // 使用者攝像頭狀態(引數為DWORD型)   
        public const int BRAC_USERSTATE_HOLDMIC         =   2;  // 使用者持有Mic狀態(引數為DWORD型)   
        public const int BRAC_USERSTATE_SPEAKVOLUME     =   3;  // 使用者當前說話音量(引數為DOUBLE型別(0.0 ~ 100.0))   
        public const int BRAC_USERSTATE_RECORDING       =   4;  // 使用者錄影(音)狀態(引數為DWORD型)   
        public const int BRAC_USERSTATE_LEVEL           =   5;  // 使用者級別(引數為DWORD型)   
        public const int BRAC_USERSTATE_NICKNAME        =   6;  // 使用者暱稱(引數為字串PCHAR型別)   
        public const int BRAC_USERSTATE_LOCALIP         =   7;  // 使用者本地IP地址(內網,引數為字串PCHAR型別)   
        public const int BRAC_USERSTATE_INTERNETIP      =   8;  // 使用者網際網路IP地址(引數為字串PCHAR型別)   
        public const int BRAC_USERSTATE_VIDEOBITRATE    =   9;  // 使用者當前的視訊位元速率(引數為DWORD型別,Bps)   
        public const int BRAC_USERSTATE_AUDIOBITRATE    =   10; // 使用者當前的音訊位元速率(引數為DWORD型別,Bps)   
        public const int BRAC_USERSTATE_P2PCONNECT      =   11; // 查詢本地使用者與指定使用者的當前P2P連線狀態(引數為DWORD型別,返回值:0 P2P不通, 1 P2P連線成功[TCP],2 P2P連線成功[UDP],3 P2P連線成功[TCP、UDP])   
        public const int BRAC_USERSTATE_NETWORKSTATUS   =   12; // 查詢指定使用者的網路狀態(引數為DWORD型別,返回值:0 優良,1 較好,2 一般,3 較差,4 非常差),注:查詢間隔需要>1s   
  
        // SDK訊息定義   
        public const int WM_GV = 0x0400 + 200;   
        public const int WM_GV_CONNECT          =   WM_GV + 1;  // 客戶端連線伺服器,wParam(BOOL)表示是否連線成功   
        public const int WM_GV_LOGINSYSTEM      =   WM_GV + 2;  // 客戶端登入系統,wParam(INT)表示自己的使用者ID號,lParam(INT)表示登入結果:0 成功,否則為出錯程式碼,參考出錯程式碼定義   
        public const int WM_GV_ENTERROOM        =   WM_GV + 3;  // 客戶端進入房間,wParam(INT)表示所進入房間的ID號,lParam(INT)表示是否進入房間:0成功進入,否則為出錯程式碼   
        public const int WM_GV_MICSTATECHANGE   =   WM_GV + 4;  // 使用者的Mic狀態變化訊息,wParam(INT)表示使用者ID號,lParam(BOOL)表示該使用者是否持有Mic   
        public const int WM_GV_USERATROOM       =   WM_GV + 5;  // 使用者進入(離開)房間,wParam(INT)表示使用者ID號,lParam(BOOL)表示該使用者是進入(TRUE)或離開(FALSE)房間   
        public const int WM_GV_LINKCLOSE        =   WM_GV + 6;  // 網路連線已關閉,該訊息只有在客戶端連線伺服器成功之後,網路異常中斷之時觸發,wParam(INT)表示連線斷開的原因   
        public const int WM_GV_ONLINEUSER       =   WM_GV + 7;  // 收到當前房間的線上使用者資訊,進入房間後觸發一次,wParam(INT)表示線上使用者數(包含自己),lParam(INT)表示房間ID   
        public const int WM_GV_FORTUNEMENU      =   WM_GV + 8;  // 使用者選擇了一項財富選單項,wParam(INT)表示使用者ID號,lParam(INT)表示財富選單標記,指示是選擇了哪一項選單   
        public const int WM_GV_ROOMWAITQUEUE    =   WM_GV + 9;  // 使用者收到當前房間等待佇列訊息,wParam(INT)表示使用者前面的佇列長度,lParam(INT)表示當前房間總的等待佇列長度   
        public const int WM_GV_ENTERREQUEST     =   WM_GV + 10; // 使用者申請進入房間訊息,wParam(INT)表示使用者ID號,lParam(BOOL)表示該使用者是申請進入(TRUE)房間或離開(FALSE)房間等待佇列   
        public const int WM_GV_CAMERASTATE      =   WM_GV + 11; // 使用者攝像頭狀態發生變化,wParam(INT)表示使用者ID號,lParam(INT)表示攝像頭的當前狀態,定義為:GV_CAMERA_STATE_XXXX   
        public const int WM_GV_CHATMODECHG      =   WM_GV + 12; // 使用者聊天模式發生變化,wParam(INT)表示使用者ID號,lParam(INT)表示使用者的當前聊天模式   
        public const int WM_GV_ACTIVESTATE      =   WM_GV + 13; // 使用者活動狀態發生變化,wParam(INT)表示使用者ID號,lParam(INT)表示使用者的當前活動狀態   
        public const int WM_GV_P2PCONNECTSTATE  =   WM_GV + 14; // 本地使用者與其它使用者的P2P網路連線狀態發生變化,wParam(INT)表示其它使用者ID號,lParam(INT)表示本地使用者與其它使用者的當前P2P網路連線狀態   
        public const int WM_GV_PRIVATEREQUEST   =   WM_GV + 21; // 使用者發起私聊請求,wParam(INT)表示發起者的使用者ID號,lParam(INT)表示私聊請求編號,標識該請求   
        public const int WM_GV_PRIVATEECHO      =   WM_GV + 22; // 使用者回覆私聊請求,wParam(INT)表示回覆者的使用者ID號,lParam(INT)為出錯程式碼   
        public const int WM_GV_PRIVATEEXIT      =   WM_GV + 23; // 使用者退出私聊,wParam(INT)表示退出者的使用者ID號,lParam(INT)為出錯程式碼   
        public const int WM_GV_EXTENDBTNPRESS   =   WM_GV + 31; // 使用者按下擴充套件按鈕,wParam(INT)表示按鈕所對應的使用者ID號,lParam(DWORD)指示按鈕(左下角)所在螢幕位置(x,y),使用者可以利用該引數顯示選單等   
        public const int WM_GV_SDKWARNING       =   WM_GV + 41; // SDK警告資訊,當SDK在執行過程中自檢發現異常狀態時,將向上層傳送該訊息,wParam(INT)表示警告程式碼,定義為:GV_ERR_WARNING_XXXX   
  
        // SDK出錯程式碼定義,其它程式碼請參考:C++ SDK目錄中的GVErrorCodeDefine.h檔案   
        public const int GV_ERR_SUCCESS         =   0;          // 成功   
  
  
        public const ulong BRAC_FUNC_VIDEO_CBDATA   =   0x00000001L ;///< 通過回撥函式輸出視訊資料   
        public const ulong BRAC_FUNC_VIDEO_AUTODISP =0x00000002L    ;///< 由SDK包處理視訊,將視訊顯示在指定的視窗上   
        public const ulong BRAC_FUNC_AUDIO_CBDATA   =   0x00000004L;    ///< 通過回撥函式輸出音訊資料   
        public const ulong BRAC_FUNC_AUDIO_AUTOPLAY =0x00000008L    ;///< 由SDK包處理音訊,直接播放   
        public const ulong BRAC_FUNC_CONFIG_LOCALINI    =0x00000010L    ;///< 生成本地配置檔案(AnyChatSDK.ini)   
        public const ulong BRAC_FUNC_FIREWALL_OPEN  =   0x00000020L;    ///< 允許SDK操作Windows防火牆,將當前應用程式加入防火牆訪問列表(避免Windows提示使用者是否阻止當前應用程式)   
        public const ulong BRAC_FUNC_CHKDEPENDMODULE    =0x00000040L    ;///< 自動檢查SDK所依賴的元件,並自動註冊   
        public const ulong BRAC_FUNC_AUDIO_VOLUMECALC=  0x00000080L;    ///< 由SDK自動計算語音的音量   
        public const ulong BRAC_FUNC_AUDIO_AUTOVOLUME=  0x00000100L;    ///< 允許SDK自動控制Mic錄音音量   
        public const ulong BRAC_FUNC_NET_SUPPORTUPNP    =0x00000200L    ;///< 允許SDK開啟使用者網路中的UPNP裝置,如果使用者的路由器或是防火牆支援UPNP協議,則可提高P2P打洞的成功率   
        public const ulong BRAC_FUNC_DISABLEDECODE = 0x00000400L;///< 禁止對收到的資料進行解碼和播放,為了提高代理客戶端的資料轉發效能,可設定該標誌,否則不能設定該標誌   
  
  
  
       
  
  
  
  
  
  
  
  
  
  
        // 音訊裝置列舉定義   
        public enum AudioDevice   
        {   
            BRAC_AD_WAVEIN  = 0,                                // 輸入裝置:Mic   
            BRAC_AD_WAVEOUT = 1                                 // 輸出裝置:Wave   
        }   
  
        public enum PixelFormat{   
            BRAC_PIX_FMT_RGB24 = 0,                     ///< Packed RGB 8:8:8, 24bpp, RGBRGB...(MEDIASUBTYPE_RGB24)   
            BRAC_PIX_FMT_RGB32,                         ///< 對應於:MEDIASUBTYPE_RGB32,Packed RGB 8:8:8, 32bpp, (msb)8A 8R 8G 8B(lsb), in cpu endianness   
            BRAC_PIX_FMT_YV12,                          ///< 對應於:MEDIASUBTYPE_YV12,Planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)   
            BRAC_PIX_FMT_YUY2,                          ///< 對應於:MEDIASUBTYPE_YUY2,Packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr   
        }   
        [StructLayout(LayoutKind.Sequential)]             
        //BitmapInfoHeader   定義了點陣圖的頭部資訊             
        public struct BITMAPINFOHEADER             
        {                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biSize;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biWidth;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biHeight;                 
            [MarshalAs(UnmanagedType.I2)]                 
            public short biPlanes;                 
            [MarshalAs(UnmanagedType.I2)]                 
            public short biBitCount;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biCompression;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biSizeImage;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biXPelsPerMeter;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biYPelsPerMeter;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biClrUsed;                 
            [MarshalAs(UnmanagedType.I4)]                 
            public Int32 biClrImportant;             
        }   
  
        // 功能模式列舉定義,API:BRAC_InitSDK 傳入引數   
        public enum FUNCMode : ulong  
        {   
            BRAC_FUNC_VIDEO_CBDATA          =   0x00000001L,    // 通過回撥函式輸出視訊資料   
            BRAC_FUNC_VIDEO_AUTODISP        =   0x00000002L,    // 由SDK包處理視訊,將視訊顯示在指定的視窗上   
            BRAC_FUNC_AUDIO_CBDATA          =   0x00000004L,    // 通過回撥函式輸出音訊資料   
            BRAC_FUNC_AUDIO_AUTOPLAY        =   0x00000008L,    // 由SDK包處理音訊,直接播放   
            BRAC_FUNC_CONFIG_LOCALINI       =   0x00000010L,    // 生成本地配置檔案(AnyChatSDK.ini)   
            BRAC_FUNC_FIREWALL_OPEN         =   0x00000020L,    // 允許SDK操作Windows防火牆,將當前應用程式加入防火牆訪問列表(避免Windows提示使用者是否阻止當前應用程式)   
            BRAC_FUNC_CHKDEPENDMODULE       =   0x00000040L,    // 自動檢查SDK所依賴的元件,並自動註冊   
            BRAC_FUNC_AUDIO_VOLUMECALC      =   0x00000080L,    // 由SDK自動計算語音的音量   
            BRAC_FUNC_AUDIO_AUTOVOLUME      =   0x00000100L,    // 允許SDK自動控制Mic錄音音量   
            BRAC_FUNC_NET_SUPPORTUPNP       =   0x00000200L,    // 允許SDK開啟使用者網路中的UPNP裝置,如果使用者的路由器或是防火牆支援UPNP協議,則可提高P2P打洞的成功率   
            BRAC_FUNC_DISABLEDECODE         =   0x00000400L     // 禁止對收到的資料進行解碼和播放,為了提高代理客戶端的資料轉發效能,可設定該標誌,否則不能設定該標誌   
        }   
  
  
  
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]   
        public struct WaveFormat   
        {   
            public short wFormatTag;   
            public short nChannels;   
            public uint nSamplesPerSec;   
            public uint nAvgBytesPerSec;   
            public short nBlockAlign;   
            public short wBitsPerSample;   
            public short cbSize;   
        }   
        #endregion  
 
        #region AnyChat Platform Core SDK 功能函式API介面封裝   
        /// <summary>   
        /// 透明通道資料回撥函式定義   
        /// </summary>   
        /// <param name="userId">使用者ID</param>   
        /// <param name="buf">緩衝區</param>   
        /// <param name="len">緩衝區長度</param>   
        /// <param name="userValue">附帶資訊</param>   
        public delegate void TransBufferCallBack(int userId, IntPtr buf, int len, int userValue);   
  
        /// <summary>   
        /// 透明通道擴充套件回撥函式定義   
        /// </summary>   
        /// <param name="userId">使用者ID</param>   
        /// <param name="buf">緩衝區</param>   
        /// <param name="len">緩衝區長度</param>   
        /// <param name="wParam">緩衝區附帶資訊1</param>   
        /// <param name="lParam">緩衝區附帶資訊2</param>   
        /// <param name="taskId">傳輸任務編號</param>   
        /// <param name="userValue">自定義引數</param>   
        public delegate void TransBufferCallBackEx(int userId, IntPtr buf, int len,int wParam,int lParam,int taskId, int userValue);   
  
        /// <summary>   
        /// 傳輸檔案回撥函式定義   
        /// </summary>   
        /// <param name="userId">使用者ID</param>   
        /// <param name="fileName">檔名</param>   
        /// <param name="filePath">檔案接收後儲存在本地的路徑</param>   
        /// <param name="fileLength">檔案長度</param>   
        /// <param name="wParam">附帶資訊1</param>   
        /// <param name="lParam">附帶資訊2</param>   
        /// <param name="taskId">傳輸任務編號</param>   
        /// <param name="userValue">自定義引數</param>   
        public delegate void TransFileCallBack(int userId, string fileName, string filePath, int fileLength, int wParam, int lParam, int taskId, int userValue);   
  
        /// <summary>   
        /// 音量變化回撥函式定義   
        /// </summary>   
        /// <param name="device">音訊裝置</param>   
        /// <param name="currentVolume">當前音量</param>   
        /// <param name="lpUserValue">附帶資訊</param>   
        public delegate void VolumeChangeCallBack(AudioDevice device, int currentVolume, int userValue);   
  
        public delegate void SDKFilterDataCallBack(IntPtr buf,int len,int userValue);   
  
        /// <summary>   
        /// 錄影回撥函式   
        /// </summary>   
        /// <param name="userId">使用者id</param>   
        /// <param name="filePath">錄影儲存路徑</param>   
        /// <param name="param">引數</param>   
        /// <param name="recordType">錄影型別,1錄影,0拍照</param>   
        /// <param name="userValue">使用者引數</param>   
        public delegate void RecordCallBack(int userId, string filePath, int param, bool recordType,int userValue);   
  
        /// <summary>   
        /// 視訊回撥函式   
        /// </summary>   
        /// <param name="userId"></param>   
        /// <param name="buf"></param>   
        /// <param name="len"></param>   
        /// <param name="bitMap"></param>   
        /// <param name="userValue"></param>   
        public delegate void VideoData_CallBack(int userId, IntPtr buf, int len, BITMAPINFOHEADER bitMap, int userValue);   
  
        /// <summary>   
        /// 聲音回撥   
        /// </summary>   
        /// <param name="userId"></param>   
        /// <param name="buf"></param>   
        /// <param name="len"></param>   
        /// <param name="format"></param>   
        /// <param name="userValue"></param>   
        public delegate void AudioData_CallBack(int userId,IntPtr buf,int len,WaveFormat format,int userValue);   
  
        /// <summary>   
        /// 訊息接收回調   
        /// </summary>   
        /// <param name="fromuserId"></param>   
        /// <param name="touserId"></param>   
        /// <param name="isserect"></param>   
        /// <param name="message"></param>   
        /// <param name="len"></param>   
        /// <param name="userValue"></param>   
        public delegate void TextMessage_CallBack(int fromuserId, int touserId, bool isserect,    
            string message, int len, int userValue);   
  
        /// <summary>   
        /// 視訊事件註冊   
        /// </summary>   
        /// <param name="format"></param>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetVideoDataCallBack")]   
        public static extern int SetVideoDataCallBack(PixelFormat format, VideoData_CallBack function,int userValue);   
  
  
           
  
        /// <summary>   
        /// SDK Filter 註冊回撥   
        /// </summary>   
        /// <param name="format"></param>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetSDKFilterDataCallBack")]   
        public static extern int SetSDKFilterDataCallBack(SDKFilterDataCallBack function, int userValue);   
  
        /// <summary>   
        /// SDK Filter 傳送資料到伺服器端   
        /// </summary>   
        /// <param name="format"></param>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SendSDKFilterData")]   
        public static extern int SendSDKFilterData(IntPtr buf, int len);   
  
           
        /// <summary>   
        /// 聲音事件註冊   
        /// </summary>   
        /// <param name="format"></param>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetAudioDataCallBack")]   
        public static extern int SetAudioDataCallBack(AudioData_CallBack function, int userValue);   
  
  
        /// <summary>   
        /// 註冊文字訊息回撥   
        /// </summary>   
        /// <param name="format"></param>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetTextMessageCallBack")]   
        public static extern int SetTextMessageCallBack(TextMessage_CallBack function, int userValue);   
  
  
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetServerAuthPass")]   
        public static extern int SetServerAuthPass(StringBuilder key);   
  
        /// <summary>   
        /// 傳送訊息   
        /// </summary>   
        /// <param name="userID">-1為所有人</param>   
        /// <param name="isSerect">僅使用者id 不為-1時有效</param>   
        /// <param name="msg">訊息內容</param>   
        /// <param name="len"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SendTextMessage")]   
        public static extern int SendTextMessage(int userID,bool isSerect,string msg,int len);   
           
        /// <summary>   
        /// 與伺服器端交換   
        /// </summary>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SendTextMessage")]   
        public static extern int SendSDKFilterData();   
        /// <summary>   
        /// 獲取使用者名稱   
        /// </summary>   
        /// <param name="userId">使用者ID</param>   
        /// <param name="userName">使用者名稱</param>   
        /// <param name="bufLen">緩衝區長度</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetUserName")]   
        public static extern int GetUserName(int userId, StringBuilder userName, int bufLen);   
  
        /// <summary>   
        /// 初始化系統   
        /// </summary>   
        /// <param name="hWnd">接收訊息視窗控制代碼,可為空</param>   
        /// <param name="funcMode">功能模式</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_InitSDK")]   
        public static extern int InitSDK(IntPtr hWnd, ulong funcMode);   
  
        /// <summary>   
        /// 設定透明通道資料回撥函式   
        /// </summary>   
        /// <param name="function">回撥函式</param>   
        /// <param name="userValue">附帶資訊</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetTransBufferCallBack")]   
        public static extern int SetTransBufferCallBack(TransBufferCallBack function, int userValue);   
  
        /// <summary>   
        /// 設定透明通道擴充套件回撥函式   
        /// </summary>   
        /// <param name="function">回撥函式</param>   
        /// <param name="userValue">附帶資訊</param>   
        /// <returns>0為成功,否則失敗</param>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetTransBufferExCallBack")]   
        public static extern int SetTransBufferExCallBack(TransBufferCallBackEx function, int userValue);   
  
        /// <summary>   
        /// 設定檔案傳輸回撥函式   
        /// </summary>   
        /// <param name="function">回撥函式</param>   
        /// <param name="userValue">附帶資訊</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetTransFileCallBack")]   
        public static extern int SetTransFileCallBack(TransFileCallBack function, int userValue);   
  
        /// <summary>   
        /// 設定音量變化回撥函式   
        /// </summary>   
        /// <param name="function">回撥函式</param>   
        /// <param name="userValue">附帶資訊</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetVolumeChangeCallBack")]   
        public static extern int SetVolumeChangeCallBack(VolumeChangeCallBack function, int userValue);   
  
        /// <summary>   
        /// 設定錄影回撥函式   
        /// </summary>   
        /// <param name="function"></param>   
        /// <param name="userValue"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetRecordSnapShotCallBack")]   
        public static extern int SetRecordCallBack(RecordCallBack function, int userValue);   
  
        /// <summary>   
        /// 連線伺服器   
        /// </summary>   
        /// <param name="serverAddr">伺服器地址</param>   
        /// <param name="port">埠號</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_Connect")]   
        public static extern int Connect(string serverAddr, int port);   
  
        /// <summary>   
        /// 登入系統   
        /// </summary>   
        /// <param name="userName">使用者名稱</param>   
        /// <param name="password">密碼</param>   
        /// <param name="passEncType">是否加密</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_Login")]   
        public static extern int Login(string userName, string password, int passEncType);   
  
        /// <summary>   
        /// 進入房間   
        /// </summary>   
        /// <param name="roomid">房間號</param>   
        /// <param name="roomPass">房間密碼</param>   
        /// <param name="passEncType">是否加密</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_EnterRoom")]   
        public static extern int EnterRoom(int roomid, string roomPass, int passEncType);   
  
        /// <summary>   
        /// 離開房間   
        /// </summary>   
        /// <param name="roomid">房間號</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_LeaveRoom")]   
        public static extern int LeaveRoom(int roomid);   
  
        /// <summary>   
        /// 登出系統   
        /// </summary>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_Logout")]   
        public static extern int Logout();   
  
        /// <summary>   
        /// 釋放所有資源   
        /// </summary>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_Release")]   
        public static extern int Release();   
  
        /// <summary>   
        /// 獲取當前房間線上使用者列表   
        /// </summary>   
        /// <param name="userIDArray">使用者列表</param>   
        /// <param name="userNum">使用者數量</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetOnlineUser")]   
        public static extern int GetOnlineUser(int[] userIDArray, ref int userNum);   
  
        /// <summary>   
        /// 查詢使用者攝像頭的狀態   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="state">當前狀態,0為沒有攝像頭,1為有但沒開啟,2為已開啟</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetCameraState")]   
        public static extern int GetCameraState(int userid, ref int state);   
  
        /// <summary>   
        /// 查詢使用者發言狀態   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="state">0為沒說話,1為正在說話</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetSpeakState")]   
        public static extern int GetSpeakState(int userid, ref int state);   
  
        /// <summary>   
        /// 查詢指定使用者相關狀態(非字串型別)   
        /// </summary>   
        /// <param name="userid">使用者編號</param>   
        /// <param name="infoname">引數名,參考常量定義:BRAC_USERSTATE_XXXX</param>   
        /// <param name="infoval">引數地址</param>   
        /// <param name="infolen">引數長度</param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_QueryUserState")]   
        public static extern int QueryUserState(int userid, int infoname, ref int infoval, int infolen);   
        // BRAC_API DWORD BRAC_QueryUserState(DWORD dwUserId, int infoname, char FAR* infoval, int infolen);   
  
        /// <summary>   
        /// 查詢指定使用者相關狀態(字串型別)   
        /// </summary>   
        /// <param name="userid">使用者編號</param>   
        /// <param name="infoname">引數名,參考常量定義:BRAC_USERSTATE_XXXX</param>   
        /// <param name="infoval">引數地址</param>   
        /// <param name="infolen">引數長度</param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_QueryUserState")]   
        public static extern int QueryUserState(int userid, int infoname, StringBuilder infoval, int infolen);   
        // BRAC_API DWORD BRAC_QueryUserState(DWORD dwUserId, int infoname, char FAR* infoval, int infolen);   
  
        /// <summary>   
        /// 顯示本地視訊畫面調節對話方塊   
        /// </summary>   
        /// <param name="parent">父窗體控制代碼</param>   
        /// <param name="caption">窗體標題</param>   
        /// <param name="dwX">X位置</param>   
        /// <param name="dwY">Y位置</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_ShowLVProperty")]   
        public static extern int ShowLVProperty(IntPtr parent, string caption, int dwX, int dwY);   
  
        /// <summary>   
        /// 操作使用者視訊   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="open">是否開啟</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_UserCameraControl")]   
        public static extern int UserCameraControl(int userid, bool open);   
  
        /// <summary>   
        /// 操作使用者語音   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="open">是否開啟</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_UserSpeakControl")]   
        public static extern int UserSpeakControl(int userid, bool open);   
  
        /// <summary>   
        /// 設定視訊顯示位置   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="hWnd">視窗控制代碼</param>   
        /// <param name="left">左位置</param>   
        /// <param name="top">上位置</param>   
        /// <param name="right">右位置</param>   
        /// <param name="bottom">底位置</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetVideoPos")]   
        public static extern int SetVideoPos(int userid, IntPtr hWnd, int left, int top, int right, int bottom);   
  
        /// <summary>   
        /// 獲取指定音訊裝置的當前音量   
        /// </summary>   
        /// <param name="device">音訊裝置</param>   
        /// <param name="volume">音量</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_AudioGetVolume")]   
        public static extern int AudioGetVolume(AudioDevice device, ref int volume);   
  
        /// <summary>   
        /// 設定指定音訊裝置的音量   
        /// </summary>   
        /// <param name="device">音訊裝置</param>   
        /// <param name="volume">音量</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_AudioSetVolume")]   
        public static extern int AudioSetVolume(AudioDevice device, int volume);   
  
        /// <summary>   
        /// 利用透明通道傳送資料   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="buf">緩衝區</param>   
        /// <param name="len">緩衝區長度</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_TransBuffer")]   
        public static extern int TransBuffer(int  userid, IntPtr buf, int len);   
  
        /// <summary>   
        /// 利用擴充套件透明通道傳送資料   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="buf">緩衝區</param>   
        /// <param name="len">緩衝區長度</param>   
        /// <param name="wParam">附帶資訊1</param>   
        /// <param name="lParam">附帶資訊2</param>   
        /// <param name="flag">特殊標誌,預設為0</param>   
        /// <param name="taskId">任務ID,新增任務後系統自動生成</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_TransBufferEx")]   
        public static extern int TransBufferEx(int userid, IntPtr buf, int len, int wParam, int lParam, int flag, ref int taskId);   
  
        /// <summary>   
        /// 傳送檔案   
        /// </summary>   
        /// <param name="userid">使用者ID</param>   
        /// <param name="localFilePath">本地檔案路徑</param>   
        /// <param name="wParam">附帶資訊1</param>   
        /// <param name="lParam">附帶資訊2</param>   
        /// <param name="flag">特殊標誌</param>   
        /// <param name="taskId">任務ID</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_TransFile")]   
        public static extern int TransFile(int userid, string localFilePath, int wParam, int lParam, int flag, ref int taskId);   
  
        /// <summary>   
        /// 開啟或關閉錄影   
        /// </summary>   
        /// <param name="userId">使用者id</param>   
        /// <param name="startRecord">是否開啟錄影</param>   
        /// <param name="flags">標誌,0為錄製視訊音訊</param>   
        /// <param name="param">引數</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_StreamRecordCtrl")]   
        public static extern int StreamRecordCtrl(int userId, bool startRecord, ulong flags, int param);   
  
        /// <summary>   
        /// 抓取視訊,對指定使用者進行拍照   
        /// </summary>   
        /// <param name="userId"></param>   
        /// <param name="flags"></param>   
        /// <param name="param"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SnapShot")]   
        public static extern int SnapShot(int userId, ulong flags, int param);   
  
        /// <summary>   
        /// 是否開啟SDK日記   
        /// </summary>   
        /// <param name="isOpen">是否開啟</param>   
        /// <returns>0為成功,否則失敗</returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_ActiveCallLog")]   
        public static extern int ActiveCallLog(bool isOpen);   
  
        /// <summary>   
        /// 設定SDK核心引數(字串型別)   
        /// </summary>   
        /// <param name="optName">引數名</param>   
        /// <param name="optval">引數值</param>   
        /// <param name="optlen">引數長度</param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetSDKOption")]   
        public static extern int SetSDKOption(int optName, string optval, int optlen);   
  
        /// <summary>   
        /// 設定SDK核心引數(非字串型別,INT、BOOL型別)   
        /// </summary>   
        /// <param name="optName">引數名,參考常量定義:BRAC_SO_XXXX</param>   
        /// <param name="optval">引數地址</param>   
        /// <param name="optlen">引數長度</param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SetSDKOption")]   
        public static extern int SetSDKOption(int optName, ref int optval, int optlen);   
  
        /// <summary>   
        /// 獲取SDK核心引數   
        /// </summary>   
        /// <param name="optName">引數名,參考常量定義:BRAC_SO_XXXX</param>   
        /// <param name="optval">儲存引數值的緩衝區地址</param>   
        /// <param name="optlen">引數緩衝區大小</param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetSDKOption")]   
        public static extern int GetSDKOption(int optName, ref int optval, int optlen);   
  
        /// <summary>   
        /// 列舉視訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <param name="deviceNum"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_EnumVideoCapture")]   
        public static extern int EnumVideoCapture(IntPtr[] deviceName, ref int deviceNum);   
  
        /// <summary>   
        /// 指定特定視訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SelectVideoCapture")]   
        public static extern int SelectVideoCapture(string deviceName);   
  
        /// <summary>   
        /// 獲取當前視訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <param name="length"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetCurVideoCapture")]   
        public static extern int GetCurVideoCapture(StringBuilder deviceName, int length);   
  
        /// <summary>   
        /// 列舉音訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <param name="deviceNum"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_EnumAudioCapture")]   
        public static extern int EnumAudioCapture(IntPtr[] deviceName, ref int deviceNum);   
  
        /// <summary>   
        /// 指定特定音訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_SelectAudioCapture")]   
        public static extern int SelectAudioCapture(string deviceName);   
  
        /// <summary>   
        /// 獲取當前音訊裝置   
        /// </summary>   
        /// <param name="deviceName"></param>   
        /// <param name="length"></param>   
        /// <returns></returns>   
        [DllImport("BRAnyChatCore.dll", EntryPoint = "BRAC_GetCurAudioCapture")]   
        public static extern int GetCurAudioCapture(StringBuilder deviceName, int length);  
 
        #endregion   
    }   
}  

其它程式碼請檢視附件