private void buttonGetTemplate_Click(object sender, EventArgs e) { uint dwCommand = 0; string[] strCommand = { "NET_DVR_GET_DOOR_STATUS_PLAN_TEMPLATE", "NET_DVR_GET_VERIFY_PLAN_TEMPLATE", "NET_DVR_GET_CARD_RIGHT_PLAN_TEMPLATE_V50" }; uint dwReturned = 0; string strTemp = null; uint dwSize = (uint)Marshal.SizeOf(m_struTemplateCfg); IntPtr ptrPlanCfg = Marshal.AllocHGlobal((int)dwSize); Marshal.StructureToPtr(m_struTemplateCfg, ptrPlanCfg, false); switch (comboBoxDeviceTypeHG.SelectedIndex) { case 0: case 1: if (comboBoxDeviceTypeHG.SelectedIndex == 0) { dwCommand = (uint)CHCNetSDK.NET_DVR_GET_DOOR_STATUS_PLAN_TEMPLATE; } else { dwCommand = (uint)CHCNetSDK.NET_DVR_GET_VERIFY_PLAN_TEMPLATE; } int templateNumberIndex; int.TryParse(textBoxTemplateNumber.Text, out templateNumberIndex); if (!CHCNetSDK.NET_DVR_GetDVRConfig(m_lUserID, dwCommand, templateNumberIndex, ptrPlanCfg, dwSize, ref dwReturned)) { Marshal.FreeHGlobal(ptrPlanCfg); strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[comboBoxDeviceTypeHG.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError()); MessageBox.Show(strTemp); return; } else { strTemp = string.Format("{0}", strCommand[comboBoxDeviceTypeHG.SelectedIndex]); g_formList.AddLog(m_lUserID, AcsDemoPublic.OPERATION_SUCC_T, strTemp); } break; case 2: dwCommand = (uint)CHCNetSDK.NET_DVR_GET_CARD_RIGHT_PLAN_TEMPLATE_V50; uint dwConSize = (uint)Marshal.SizeOf(m_struTemplateCond); m_struTemplateCond.dwSize = dwConSize; // limited input data guarantee parse success uint.TryParse(textBoxTemplateNumber.Text, out m_struTemplateCond.dwPlanTemplateNumber); ushort.TryParse(textBoxLocalControllerID.Text, out m_struTemplateCond.wLocalControllerID); IntPtr ptrPlanCon = Marshal.AllocHGlobal((int)dwConSize); Marshal.StructureToPtr(m_struTemplateCond, ptrPlanCon, false); IntPtr ptrDwReturned = Marshal.AllocHGlobal(4); if (!CHCNetSDK.NET_DVR_GetDeviceConfig(m_lUserID, dwCommand, 1, ptrPlanCon, dwConSize, ptrDwReturned, ptrPlanCfg, dwSize)) { Marshal.FreeHGlobal(ptrPlanCfg); Marshal.FreeHGlobal(ptrPlanCon); Marshal.FreeHGlobal(ptrDwReturned); strTemp = string.Format("{0} FAIL, ERROR CODE {1}", strCommand[comboBoxDeviceTypeHG.SelectedIndex], CHCNetSDK.NET_DVR_GetLastError()); MessageBox.Show(strTemp); return; } else { dwReturned = (uint)Marshal.ReadInt32(ptrDwReturned); Marshal.FreeHGlobal(ptrDwReturned); Marshal.FreeHGlobal(ptrPlanCon); strTemp = string.Format("{0}", strCommand[comboBoxDeviceTypeHG.SelectedIndex]); g_formList.AddLog(m_lUserID, AcsDemoPublic.OPERATION_SUCC_T, strTemp); } break; default: Marshal.FreeHGlobal(ptrPlanCfg); MessageBox.Show("unknown command"); return; } m_struTemplateCfg = (CHCNetSDK.NET_DVR_PLAN_TEMPLATE)Marshal.PtrToStructure(ptrPlanCfg, typeof(CHCNetSDK.NET_DVR_PLAN_TEMPLATE)); if (1 == m_struTemplateCfg.byEnable) { checkBoxEnableHG.Checked = true; } else { checkBoxEnableHG.Checked = false; } if (m_iEncodeType == 6) { textBoxTemplateName.Text = System.Text.Encoding.UTF8.GetString(m_struTemplateCfg.byTemplateName); } else { Encoding ec = System.Text.Encoding.GetEncoding("gb2312"); textBoxTemplateName.Text = ec.GetString(m_struTemplateCfg.byTemplateName); } textBoxWeekPlanNo.Text = m_struTemplateCfg.dwWeekPlanNo.ToString(); UpdateLstGroupNoP(); Marshal.FreeHGlobal(ptrPlanCfg); }