private void btnSetParam_Click(object sender, EventArgs e) { SdkClass.NET_ITS_UPLOAD_CFG struUploadCfg = new SdkClass.NET_ITS_UPLOAD_CFG(); IntPtr pstruUploadCfg = Marshal.AllocHGlobal(Marshal.SizeOf(struUploadCfg)); Marshal.StructureToPtr(struUploadCfg, pstruUploadCfg, true); int dwReturned = 0; int ret = -1; if ((ret = SdkClass.NET_DVR_GetDVRConfig(iUid, SdkClass.NET_ITS_GET_UPLOAD_CFG, -1, pstruUploadCfg, Marshal.SizeOf(struUploadCfg), ref dwReturned)) == 1) { struUploadCfg = (SdkClass.NET_ITS_UPLOAD_CFG)Marshal.PtrToStructure(pstruUploadCfg, typeof(SdkClass.NET_ITS_UPLOAD_CFG)); struUploadCfg.struRemoteDataHost1.struHostAddr.sIpV4 = this.ipaddrListenIP.Text == "..." ? "0.0.0.0" : this.ipaddrListenIP.Text; try { struUploadCfg.struRemoteDataHost1.wHostPort = Convert.ToInt16(this.tbListenPort.Text.ToString()); struUploadCfg.struRemoteDataHost1.wUploadInterval = Convert.ToInt16(this.tbUpIntTime.Text.ToString()); struUploadCfg.struRemoteDataHost1.dwUploadTimeOut = Convert.ToInt16(this.tbUpExtraTime.Text.ToString()); } catch (System.Exception ex) { MessageBox.Show("参数输入异常,原因是:" + ex.ToString()); } struUploadCfg.struRemoteDataHost1.byUploadStrategy = 0; struUploadCfg.struRemoteDataHost1.bySuspendUpload = this.chbSuspend.Checked?(byte)0:(byte)1; struUploadCfg.struRemoteDataHost1.dwDataType |= 0x01;//卡口数据 Marshal.StructureToPtr(struUploadCfg, pstruUploadCfg, false); if ((ret = SdkClass.NET_DVR_SetDVRConfig(iUid, SdkClass.NET_ITS_SET_UPLOAD_CFG, -1, pstruUploadCfg, Marshal.SizeOf(struUploadCfg))) == 1) { if (SdkClass.NET_DVR_RebootDVR(iUid) == 1) { MessageBox.Show("设置参数成功!等待重启完成,重新运行软件!"); } else { MessageBox.Show("设置参数成功!手动重启后生效!"); } } else { ret = SdkClass.NET_DVR_GetLastError(); MessageBox.Show("设置参数失败!错误码为:" + ret); } } else { ret = SdkClass.NET_DVR_GetLastError(); MessageBox.Show("获取参数失败!错误码为:" + ret); } Marshal.FreeHGlobal(pstruUploadCfg);//释放分配的非托管内存。 }
private void btnSetParam_Click(object sender, EventArgs e) { SdkClass.NET_ITS_UPLOAD_CFG struUploadCfg = new SdkClass.NET_ITS_UPLOAD_CFG(); IntPtr pstruUploadCfg = Marshal.AllocHGlobal(Marshal.SizeOf(struUploadCfg)); Marshal.StructureToPtr(struUploadCfg, pstruUploadCfg, true); int dwReturned = 0; int ret = -1 ; if ((ret = SdkClass.NET_DVR_GetDVRConfig(iUid, SdkClass.NET_ITS_GET_UPLOAD_CFG, -1, pstruUploadCfg, Marshal.SizeOf(struUploadCfg), ref dwReturned)) == 1) { struUploadCfg = (SdkClass.NET_ITS_UPLOAD_CFG)Marshal.PtrToStructure(pstruUploadCfg, typeof(SdkClass.NET_ITS_UPLOAD_CFG)); struUploadCfg.struRemoteDataHost1.struHostAddr.sIpV4 = this.ipaddrListenIP.Text == "..." ? "0.0.0.0" : this.ipaddrListenIP.Text; try { struUploadCfg.struRemoteDataHost1.wHostPort = Convert.ToInt16(this.tbListenPort.Text.ToString()); struUploadCfg.struRemoteDataHost1.wUploadInterval = Convert.ToInt16(this.tbUpIntTime.Text.ToString()); struUploadCfg.struRemoteDataHost1.dwUploadTimeOut = Convert.ToInt16(this.tbUpExtraTime.Text.ToString()); } catch (System.Exception ex) { MessageBox.Show("参数输入异常,原因是:" + ex.ToString()); } struUploadCfg.struRemoteDataHost1.byUploadStrategy = 0; struUploadCfg.struRemoteDataHost1.bySuspendUpload = this.chbSuspend.Checked?(byte)0:(byte)1; struUploadCfg.struRemoteDataHost1.dwDataType |= 0x01;//卡口数据 Marshal.StructureToPtr(struUploadCfg, pstruUploadCfg, false); if ((ret = SdkClass.NET_DVR_SetDVRConfig(iUid, SdkClass.NET_ITS_SET_UPLOAD_CFG, -1, pstruUploadCfg, Marshal.SizeOf(struUploadCfg))) == 1) { if (SdkClass.NET_DVR_RebootDVR(iUid) == 1) { MessageBox.Show("设置参数成功!等待重启完成,重新运行软件!"); } else { MessageBox.Show("设置参数成功!手动重启后生效!"); } } else { ret = SdkClass.NET_DVR_GetLastError(); MessageBox.Show("设置参数失败!错误码为:" + ret); } } else { ret = SdkClass.NET_DVR_GetLastError(); MessageBox.Show("获取参数失败!错误码为:" + ret); } Marshal.FreeHGlobal(pstruUploadCfg);//释放分配的非托管内存。 }