예제 #1
0
        private void btnLogon_Click(object sender, EventArgs e)
        {
            if ("Logon" == btnLogon.Text)   //登陆
            {
                LogonPara tInfo = new LogonPara();
                tInfo.iSize    = Marshal.SizeOf(tInfo);
                tInfo.iNvsPort = Int32.Parse(textPort.Text);
                tInfo.cNvsIP   = new char[32];
                Array.Copy(textIP.Text.ToCharArray(), tInfo.cNvsIP, textIP.Text.Length);
                tInfo.cUserName = new char[16];
                Array.Copy(textUser.Text.ToCharArray(), tInfo.cUserName, textUser.Text.Length);
                tInfo.cUserPwd = new char[16];
                Array.Copy(textPwd.Text.ToCharArray(), tInfo.cUserPwd, textPwd.Text.Length);

                IntPtr intptr = Marshal.AllocCoTaskMem(tInfo.iSize);
                Marshal.StructureToPtr(tInfo, intptr, true); //false容易造成内存泄漏
                Int32 iLogonId = NVSSDK.NetClient_Logon_V4(0, intptr, tInfo.iSize);
                Marshal.FreeHGlobal(intptr);                 //释放分配的非托管内存。
                if (iLogonId < 0)
                {
                    MessageBox.Show("logon failed!");
                    return;
                }
            }
            else  //注销
            {
                btnLogon.Text = "Logon";
                if (m_iLogonId < 0)
                {
                    return;
                }

                //断开视频连接
                DisConnectVideo();

                //回复按钮状态

                NVSSDK.NetClient_Logoff(m_iLogonId);
                m_iLogonId = -1;
            }
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            LogonActiveServer tInfo = new LogonActiveServer();

            tInfo.iSize     = Marshal.SizeOf(tInfo);
            tInfo.cUserName = new char[16];
            Array.Copy(textUser.Text.ToCharArray(), tInfo.cUserName, textUser.Text.Length);
            tInfo.cUserPwd = new char[16];
            Array.Copy(textPwd.Text.ToCharArray(), tInfo.cUserPwd, textPwd.Text.Length);
            tInfo.cProductID = new char[32];

            Array.Copy("ID0000801941341231130644".ToCharArray(), tInfo.cProductID, "ID0000801941341231130644".Length);
            //IntPtr intptr = Marshal.AllocCoTaskMem(tInfo.iSize);
            //Marshal.StructureToPtr(tInfo, intptr, true);//false容易造成内存泄漏

            //LogonPara tInfo = new LogonPara();
            //tInfo.iSize = Marshal.SizeOf(tInfo);
            //tInfo.iNvsPort = Int32.Parse(textPort.Text);
            //tInfo.cNvsIP = new char[32];
            //Array.Copy(textIP.Text.ToCharArray(), tInfo.cNvsIP, textIP.Text.Length);
            //tInfo.cUserName = new char[16];
            //Array.Copy(textUser.Text.ToCharArray(), tInfo.cUserName, textUser.Text.Length);
            //tInfo.cUserPwd = new char[16];
            //Array.Copy(textPwd.Text.ToCharArray(), tInfo.cUserPwd, textPwd.Text.Length);

            IntPtr intptr = Marshal.AllocCoTaskMem(tInfo.iSize);

            Marshal.StructureToPtr(tInfo, intptr, true);//false容易造成内存泄漏
            Int32 iLogonId = NVSSDK.NetClient_Logon_V4(4, intptr, tInfo.iSize);

            Marshal.FreeHGlobal(intptr);//释放分配的非托管内存。
            if (iLogonId < 0)
            {
                MessageBox.Show("logon failed!");
                return;
            }
        }