how to pass the value from one function to another function

Pergunta how to pass the value from one function to another function

  • Wednesday, June 25, 2008 2:07 PM
     
      Has Code
    Hi,

    In the Below code snippet i am getting an error saying that "Null reference Exception"
    at  line error = m_FPM.CreateTemplate(finger_info, fp_image, m_RegMin1);} when i keep a quick watch on m_RegMin1 , i am not able to get its value passed  from
    InitButton click function to Capture1 function. can somebody please let me know what shld i do . m_Regmin1 is initialized in InitButton function i need to get its value in the capture function.
    using System; 
    using System.Collections; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Web; 
    using System.Web.SessionState; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.HtmlControls; 
    using System.IO; 
    using SecuGen.FDxSDKPro.Windows; 
    using System.Windows.Forms; 
     
     
     
    namespace Sample 
        /// <summary> 
        /// Summary description for WebForm1. 
        /// </summary> 
        public class Enroll : System.Web.UI.Page 
     
     
        { 
            private SGFingerPrintManager m_FPM;       
            private Int32 m_ImageWidth; 
            private Int32 m_ImageHeight; 
            private Int32 m_Dpi; 
            private SGFPMSecurityLevel m_SecurityLevel; 
     
            private Byte[] m_RegMin1; 
            private Byte[] m_RegMin2; 
            private Byte[] m_VrfMin; 
            private Byte[] m_StoredTemplate; 
            protected System.Web.UI.WebControls.Button BtnCapture1; 
            protected System.Web.UI.WebControls.Button BtnCapture2; 
            protected System.Web.UI.WebControls.Image pictureBoxR1; 
            protected System.Web.UI.WebControls.Image pictureBoxR2; 
            protected System.Web.UI.WebControls.Button BtnRegister; 
            protected System.Web.UI.WebControls.Label Label1; 
            protected System.Web.UI.WebControls.DropDownList comboBoxDeviceName; 
            protected System.Web.UI.WebControls.DropDownList comboBoxSelFinger; 
            protected System.Web.UI.WebControls.Label Label2; 
            protected System.Web.UI.WebControls.RadioButtonList groupBox4; 
            protected System.Web.UI.WebControls.RadioButton[] m_RadioButton; 
            protected System.Web.UI.WebControls.Label Label3; 
            protected System.Web.UI.WebControls.RadioButton FPPosUnknown; 
            protected System.Web.UI.WebControls.RadioButton FPPosLeftLittle; 
            protected System.Web.UI.WebControls.RadioButton FPPosLeftIndex; 
            protected System.Web.UI.WebControls.RadioButton FPPosLeftThumb; 
            protected System.Web.UI.WebControls.RadioButton FPPosLeftMiddle; 
            protected System.Web.UI.WebControls.RadioButton FPPosLeftRing; 
            protected System.Web.UI.WebControls.RadioButton FPPosRightThumb; 
            protected System.Web.UI.WebControls.RadioButton FPPosRightIndex; 
            protected System.Web.UI.WebControls.RadioButton FPPosRightMiddle; 
            protected System.Web.UI.WebControls.RadioButton FPPosRightRing; 
            protected System.Web.UI.WebControls.RadioButton FPPosRightLittle; 
            protected System.Web.UI.WebControls.Button InitBtn; 
            private System.Windows.Forms.ProgressBar progressBar_R1; 
            private System.Windows.Forms.ProgressBar progressBar_R2; 
     
     
            static private bool   m_DeviceOpened; 
            private FileStream inStream; 
     
     
            private void Page_Load(object sender, System.EventArgs e) 
            { 
                // Put user code to initialize the page here 
     
                EnableButtons(false); 
                // Init Button 
                m_RadioButton = new System.Web.UI.WebControls.RadioButton[11]; 
                m_RadioButton[0] = FPPosUnknown; 
                m_RadioButton[1] = FPPosRightThumb; 
                m_RadioButton[2] = FPPosRightIndex; 
                m_RadioButton[3] = FPPosRightMiddle; 
                m_RadioButton[4] = FPPosRightRing; 
                m_RadioButton[5] = FPPosRightLittle; 
                m_RadioButton[6] = FPPosLeftThumb; 
                m_RadioButton[7] = FPPosLeftIndex; 
                m_RadioButton[8] = FPPosLeftMiddle; 
                m_RadioButton[9] = FPPosLeftRing; 
                m_RadioButton[10] = FPPosLeftLittle; 
     
                comboBoxDeviceName.SelectedIndex = 3
                comboBoxSelFinger.SelectedIndex = 2
     
                m_SecurityLevel = SGFPMSecurityLevel.NORMAL; 
                m_StoredTemplate = null
                m_ImageWidth = 260
                m_ImageHeight = 300
                m_Dpi = 500
     
                if (!IsPostBack) 
                { 
                    m_FPM = new SGFingerPrintManager(); 
                    Session ["DEV"] = m_FPM; 
                } 
                else 
                { 
                    m_FPM = Session["DEV"] as SGFingerPrintManager; 
                } 
     
                Label3.Text = "Click Init Button"
     
            } 
     
            #region Web Form Designer generated code 
            override protected void OnInit(EventArgs e) 
            { 
                // 
                // CODEGEN: This call is required by the ASP.NET Web Form Designer. 
                // 
                InitializeComponent(); 
                base.OnInit(e); 
            } 
             
            /// <summary> 
            /// Required method for Designer support - do not modify 
            /// the contents of this method with the code editor. 
            /// </summary> 
            private void InitializeComponent() 
            {     
                this.BtnCapture1.Click += new System.EventHandler(this.BtnCapture1_Click); 
                this.BtnCapture2.Click += new System.EventHandler(this.BtnCapture2_Click); 
                this.BtnRegister.Click += new System.EventHandler(this.BtnRegister_Click); 
                this.InitBtn.Click += new System.EventHandler(this.InitBtn_Click); 
                this.Load += new System.EventHandler(this.Page_Load); 
     
            } 
            #endregion 
     
            private  void InitBtn_Click(object sender, System.EventArgs e) 
            { 
                Int32 error; 
                SGFPMDeviceName device_name = SGFPMDeviceName.DEV_UNKNOWN; 
                Int32 device_id = (Int32)SGFPMPortAddr.USB_AUTO_DETECT; 
     
                m_DeviceOpened = false
     
                // Get device name 
                if (comboBoxDeviceName.SelectedItem.Text == "USB FDU02") 
                    device_name = SGFPMDeviceName.DEV_FDU02; 
                else if (comboBoxDeviceName.SelectedItem.Text == "USB FDU03") 
                    device_name = SGFPMDeviceName.DEV_FDU03; 
                else if (comboBoxDeviceName.SelectedItem.Text == "USB FDU04") 
                    device_name = SGFPMDeviceName.DEV_FDU04; 
              
                if (device_name !=  SGFPMDeviceName.DEV_UNKNOWN) 
                error = m_FPM.Init(device_name); 
                else 
                error = m_FPM.InitEx(m_ImageWidth, m_ImageHeight, m_Dpi); 
     
                if (error == (Int32)SGFPMError.ERROR_NONE) 
                { 
                    SGFPMDeviceInfoParam pInfo = new SGFPMDeviceInfoParam(); 
                    m_FPM.GetDeviceInfo(pInfo); 
                    m_ImageWidth = pInfo.ImageWidth; 
                    m_ImageHeight = pInfo.ImageHeight; 
                 
                    EnableButtons(true); 
                    Label3.Text = "Initialization Success"
                } 
                else 
                { 
                    EnableButtons(false); 
                    Label3.Text = "Init() Error " + error; 
                    return; 
                } 
     
     
                // Set template format to ANSI 378 
                error = m_FPM.SetTemplateFormat(SGFPMTemplateFormat.ANSI378); 
              
                // Get Max template size 
                Int32 max_template_size = 0
                error = m_FPM.GetMaxTemplateSize(ref max_template_size); 
     
                m_RegMin1 = new Byte[max_template_size]; 
                m_RegMin2 = new Byte[max_template_size]; 
                m_VrfMin  = new Byte[max_template_size]; 
     
                // OpenDevice if device is selected 
                if (device_name != SGFPMDeviceName.DEV_UNKNOWN) 
                { 
                    error = m_FPM.OpenDevice(device_id); 
                    if (error == (Int32)SGFPMError.ERROR_NONE) 
                    { 
                        m_DeviceOpened = true
                    } 
                    else 
                    { 
                        Label3.Text = "OpenDevice() Error : " + error; 
                        EnableButtons(false); 
                    }                
                } 
            } 
     
     
            ///////////////////////////////////// 
            private void BtnCapture1_Click(object sender, System.EventArgs e) 
            { 
                try 
                { 
                    Byte[] fp_image = new Byte[m_ImageWidth*m_ImageHeight]; 
                    Int32 error = (Int32)SGFPMError.ERROR_NONE; 
                    Int32 img_qlty = 0
              
                if(m_DeviceOpened) 
                        error = m_FPM.GetImage(fp_image); 
                    else 
                        error = GetImageFromFile(fp_image); 
     
                     if (error == (Int32)SGFPMError.ERROR_NONE) 
                    { 
                        m_FPM.GetImageQuality(m_ImageWidth, m_ImageHeight, fp_image, ref img_qlty); 
                        //progressBar_R1.Value = img_qlty
     
                        //DrawImage(fp_image); 
     
                        SGFPMFingerInfo finger_info = new SGFPMFingerInfo(); 
                        finger_info.FingerNumber = (SGFPMFingerPosition)comboBoxSelFinger.SelectedIndex; 
                        finger_info.ImageQuality = (Int16)img_qlty; 
                        finger_info.ImpressionType = (Int16)SGFPMImpressionType.IMPTYPE_LP; 
                        finger_info.ViewNumber = 1
                          
     
                        try{ 
                         // CreateTemplate 
                            error = m_FPM.CreateTemplate(finger_info, fp_image, m_RegMin1);} 
                         catch(Exception ex) 
                        { Console.WriteLine(ex.ToString());} 
                  
                        if (error == (Int32)SGFPMError.ERROR_NONE) 
                        { 
                            Label3.Text = "First image is captured"
                            m_FPM.CloseDevice(); 
                        } 
                        else 
                            Label3.Text = "GetMinutiae() Error : " + error; 
                    } 
                    else 
                             
     
                        Label3.Text = "GetImage() Error : " + error; 
                 
                } 
                catch(Exception ex) 
                { 
                    Console.Write(ex.ToString()); 
                } 
                finally 
                       { 
                    if (m_DeviceOpened) m_FPM.CloseDevice(); 
                    m_DeviceOpened = false
     
                       } 
           
            } 

All Replies