473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how can i create dll from cpp class for using in c#

can some one tell how can convert this class to c# class
or convert it to dll for using in c# app
Expand|Select|Wrap|Line Numbers
  1. // FTDI_loadDlg.cpp : ±¸اِ ئؤہد
  2. //
  3.  
  4. #include "dos.h"
  5. #include "stdafx.h"
  6. #include "IRIBIO_API_TEST.h"
  7. #include "IRIBIO_API_TESTDlg.h"
  8. #include "return_code.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13.  
  14. //////////////////////////////////////////////////////////////////////////////////////////////
  15. //DECLARATION
  16. //////////////////////////////////////////////////////////////////////////////////////////////
  17.  
  18. //define
  19. #define TRANSFER_DATA_SIZE    4
  20. #define ID_LENGTH_SIZE        20
  21. #define CHECKSUM_DATA_SIZE    27
  22. #define TOTAL_PROTOCOL_SIZE 32
  23. #define TOTAL_PERSON_SIZE    150
  24. #define ID_STR_LENGTH_SIZE    21
  25. #define    MAX_TEMPLATE_SIZE    5000
  26. #define MAX_SIZE            10000
  27. //string length need one byte more than ID_LENGTH_SIZE to record '\0'
  28. #define USB_NOT_FOUND        false
  29. #define USB_FOUND            true
  30.  
  31.  
  32.  
  33. typedef unsigned char ReturnCode;
  34.  
  35. //data structure
  36. typedef struct RxBufferReturnData //default protocol
  37. {
  38.     unsigned char    RxTemplateData[MAX_SIZE];
  39.     int                RxTemplateLength;
  40.     unsigned char    RxDataIDTotal[TOTAL_PERSON_SIZE*ID_LENGTH_SIZE];
  41.     unsigned char    RxDataID[ID_LENGTH_SIZE];
  42.     unsigned char    RxDataIDTotalLength;
  43.     ReturnCode        RxCode;
  44. }ReturnData;
  45.  
  46. //global variable
  47. ReturnData            RxData={0x00};
  48. char                g_ID[256];
  49. char                g_FilePath[256];
  50. char                null_ID[256];
  51. unsigned char        FileName[256];
  52. char                ReadBuffer[MAX_SIZE] = {0};
  53. bool                g_USBStatus = USB_NOT_FOUND;
  54. bool                UsbFoundMessageOutOnce = false;
  55. bool                g_USBStatusMessageOutOnce = false;
  56. bool                g_hEvent = false;
  57. bool                g_GetTemplate = false;
  58. bool                g_Deletion = false;
  59. HANDLE                hEvent = NULL;
  60. HANDLE                hThread = NULL;
  61. DWORD                g_WaitForSingleObjectStatus;
  62. bool                g_WaitForSingleObjectStart = false;
  63. bool                g_Cancelation = false;
  64. bool                g_ContinueCommnad = false;
  65. bool                g_DoubleRegister = false;
  66. bool                g_RegProc = false;
  67. bool                g_CertProc = false;
  68. //CRITICAL_SECTION    cs;
  69.  
  70. //function declaration
  71. void GetID(char *g_ID);//get ID from CEdit
  72. void ResultMessageTextOut(ReturnCode DlgRCode);//return code switch
  73. void MyAfxMessageBox( char* str );//for logging
  74. void PutStaticMessage(int DefinedMSG);//text handle by using AfxGetApp()
  75. void PutList();//get ID data from DLL
  76. int SaveTemplate(ReturnData RxData);
  77. int ReadTemplate(char *g_ID);
  78. void MemoryDumpData(ReturnData *Src, ReturnData *Dst);
  79. UINT EventHandlerFunc(LPVOID lpParam);
  80.  
  81. //CALLBACK
  82. //declaration function pointer
  83. typedef void(*FUNCP)(ReturnData *);
  84. typedef void(*UsbFUNCP)(bool);
  85. //typedef void(__stdcall *FUNCP)(ReturnData *);
  86. //typedef void(__stdcall *UsbFUNCP)(bool);
  87.  
  88. //call back function declaration
  89. void RxBufferReturnDataCallBack(ReturnData *);
  90. void RxBufferReturnDataCallBackEx(ReturnData *);
  91. void DllUsbCheckCallBack(bool g_USBStatus);
  92.  
  93. //thread
  94. unsigned __stdcall WaitThread(void *vpCallback);
  95.  
  96. //import method form DLL
  97. extern "C" __declspec(dllimport) void _stdcall IrisInit();
  98. extern "C" __declspec(dllimport) void _stdcall IrisRegister(FUNCP pCallBack = NULL, char *RxTxID = NULL);
  99. extern "C" __declspec(dllimport) void _stdcall IrisRegisterEx(FUNCP pCallback = NULL, char *RxTxID = NULL);
  100. extern "C" __declspec(dllimport) void _stdcall IrisMsgBoxOk();
  101. extern "C" __declspec(dllimport) void _stdcall IrisCertify(FUNCP pCallBack = NULL, char *RxTxID = NULL);
  102. extern "C" __declspec(dllimport) void _stdcall IrisIDDelete(FUNCP pCallBack = NULL, char *RxTxID = NULL);
  103. extern "C" __declspec(dllimport) void _stdcall IrisCancel(FUNCP pCallBack = NULL);
  104. extern "C" __declspec(dllimport) void _stdcall IrisIDSave(FUNCP pCallBack = NULL);
  105. extern "C" __declspec(dllimport) void _stdcall IrisGetIDList(FUNCP pCallBack = NULL);
  106. extern "C" __declspec(dllimport) void _stdcall IrisGetTemplate(FUNCP pCallBack = NULL, char *RxTxID = NULL);
  107. extern "C" __declspec(dllimport) void _stdcall IrisPutTemplate(FUNCP pCallBack = NULL, char *RxTxID = NULL, ReturnData *TxData = NULL);
  108. //extern "C" __declspec(dllimport) void _stdcall IrisLampOn();
  109. extern "C" __declspec(dllimport) void _stdcall IrisUSBCheck(UsbFUNCP pUsbCallBack = NULL);
  110. extern "C" __declspec(dllimport) void _stdcall IrisModuleOpen();
  111. extern "C" __declspec(dllimport) void _stdcall IrisModuleClose();
  112.  
  113. //log file
  114. #define LOGFILE_PATH       "Debug.txt"
  115. char debugMsg[100];
  116. static bool g_MyMsg = true;
  117. void LogFileOut(char *LogFile, unsigned char *data);
  118. #define API_DEBUG
  119. #define ID_VERIFY
  120. /////////////////////////////////////////////////////////////////////////////////////////////////
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. class CAboutDlg : public CDialog
  133. {
  134. public:
  135.     CAboutDlg();
  136.  
  137. protected:
  138.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV ءِ؟ّہش´د´ظ.
  139.  
  140.     // ±¸اِہش´د´ظ.
  141. protected:
  142.     DECLARE_MESSAGE_MAP()
  143. };
  144.  
  145. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  146. {
  147.     CDialog::DoDataExchange(pDX);
  148. }
  149.  
  150. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  151. END_MESSAGE_MAP()
  152.  
  153.  
  154. // CFTDI_loadDlg ´ëب* »َہع
  155. CFTDI_loadDlg::CFTDI_loadDlg(CWnd* pParent /*=NULL*/)
  156. : CDialog(CFTDI_loadDlg::IDD, pParent)
  157. {
  158.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  159. }
  160.  
  161. void CFTDI_loadDlg::DoDataExchange(CDataExchange* pDX)
  162. {
  163.     CDialog::DoDataExchange(pDX);
  164.     DDX_Control(pDX, ID_STATUS_LST, m_StatusInfo);
  165.     DDX_Control(pDX, IDC_ID_EDT, m_ID);
  166. }
  167.  
  168. BEGIN_MESSAGE_MAP(CFTDI_loadDlg, CDialog)
  169.     ON_WM_SYSCOMMAND()
  170.     ON_WM_PAINT()
  171.     ON_WM_QUERYDRAGICON()
  172.     //}}AFX_MSG_MAP
  173.     ON_BN_CLICKED(IDC_REGISTRATION_BTN, &CFTDI_loadDlg::OnBnClickedRegistrationBtn)
  174.     ON_BN_CLICKED(IDC_CERTIFICATION_BTN, &CFTDI_loadDlg::OnBnClickedCertificationBtn)
  175.     ON_BN_CLICKED(IDC_SAVE_BTN, &CFTDI_loadDlg::OnBnClickedSaveBtn)
  176.     ON_BN_CLICKED(IDC_CANCEL_BTN, &CFTDI_loadDlg::OnBnClickedCancelBtn)
  177.     ON_BN_CLICKED(IDC_DELETE_BTN, &CFTDI_loadDlg::OnBnClickedDeleteBtn)
  178.     //ON_BN_CLICKED(IDC_LAMP_BTN, &CFTDI_loadDlg::OnBnClickedLampBtn)
  179.     ON_BN_CLICKED(IDC_LIST_BTN, &CFTDI_loadDlg::OnBnClickedListBtn)
  180.     ON_BN_CLICKED(IDC_CLOSE_BTN, &CFTDI_loadDlg::OnBnClickedCloseBtn)
  181.     ON_LBN_SELCHANGE(ID_STATUS_LST, &CFTDI_loadDlg::OnLbnSelchangeStatusLst)
  182.     ON_BN_CLICKED(IDC_GET_IRIS_BTN, &CFTDI_loadDlg::OnBnClickedGetIrisBtn)
  183.     ON_BN_CLICKED(IDC_PUT_IRIS_BTN, &CFTDI_loadDlg::OnBnClickedPutIrisBtn)
  184.     ON_BN_CLICKED(IDC_REG_PROCESS_BTN, &CFTDI_loadDlg::OnBnClickedRegProcessBtn)
  185.     ON_BN_CLICKED(IDC_CERT_PROCESS_BTN, &CFTDI_loadDlg::OnBnClickedIDProcessBtn)
  186.     ON_BN_CLICKED(IDC_PORT_OPEN_BTN, &CFTDI_loadDlg::OnBnClickedPortOpenBtn)
  187.     ON_BN_CLICKED(IDC_PORT_CLOSE_BTN, &CFTDI_loadDlg::OnBnClickedPortCloseBtn)
  188. END_MESSAGE_MAP()
  189.  
  190.  
  191. // CFTDI_loadDlg ¸ق½أءِ أ³¸®±â
  192.  
  193. BOOL CFTDI_loadDlg::OnInitDialog()
  194. {
  195.     CDialog::OnInitDialog();
  196.  
  197.     // ½أ½؛إغ ¸ق´؛؟، "ء¤؛¸..." ¸ق´؛ ا׸ٌہ» أك°،اص´د´ظ.
  198.  
  199.     // ہج ´ëب* »َہعہا ¾ئہجؤـہ» ¼³ء¤اص´د´ظ. ہہ؟ë اء·خ±×·¥ہا ءض أ¢ہج ´ëب* »َہع°، ¾ئ´ز °و؟ى؟،´آ
  200.     // اء·¹ہس؟ِإ©°، ہج ہغ¾÷ہ» ہعµ؟ہ¸·خ ¼ِاàاص´د´ظ.
  201.     SetIcon(m_hIcon, TRUE);            // إ« ¾ئہجؤـہ» ¼³ء¤اص´د´ظ.
  202.     SetIcon(m_hIcon, FALSE);        // ہغہ؛ ¾ئہجؤـہ» ¼³ء¤اص´د´ظ.
  203.  
  204.     //init  module
  205.     //IrisInit();
  206.     PutStaticMessage(MESSAGE_WELCOME);
  207.     IrisUSBCheck(&DllUsbCheckCallBack);
  208.     hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  209.     hThread = AfxBeginThread(EventHandlerFunc, NULL);
  210.     //InitializeCriticalSection(&cs); 
  211.  
  212.     return TRUE;  // ئ÷ؤ؟½؛¸¦ ؤءئ®·ر؟، ¼³ء¤ادءِ ¾تہ¸¸é TRUE¸¦ ¹فب¯اص´د´ظ.
  213. }
  214.  
  215. void CFTDI_loadDlg::OnSysCommand(UINT nID, LPARAM lParam)
  216. {
  217.     CDialog::OnSysCommand(nID, lParam);
  218. }
  219.  
  220. // ´ëب* »َہع؟، أض¼زب* ´ـأك¸¦ أك°،از °و؟ى ¾ئہجؤـہ» ±×¸®·ء¸é
  221. //  ¾ئ·، ؤعµه°، ات؟ناص´د´ظ. ¹®¼*/؛ن ¸ًµ¨ہ» »ç؟ëاد´آ MFC ہہ؟ë اء·خ±×·¥ہا °و؟ى؟،´آ
  222. //  اء·¹ہس؟ِإ©؟،¼* ہج ہغ¾÷ہ» ہعµ؟ہ¸·خ ¼ِاàاص´د´ظ.
  223.  
  224. void CFTDI_loadDlg::OnPaint()
  225. {
  226.     if (IsIconic())
  227.     {
  228.         CPaintDC dc(this); // ±×¸®±â¸¦ ہ§ار µً¹ظہج½؛ ؤءإط½؛ئ®
  229.  
  230.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  231.  
  232.         // إ¬¶َہج¾ًئ® »ç°¢اü؟،¼* ¾ئہجؤـہ» °،؟îµ¥؟، ¸آأن´د´ظ.
  233.         int cxIcon = GetSystemMetrics(SM_CXICON);
  234.         int cyIcon = GetSystemMetrics(SM_CYICON);
  235.         CRect rect;
  236.         GetClientRect(&rect);
  237.         int x = (rect.Width() - cxIcon + 1) / 2;
  238.         int y = (rect.Height() - cyIcon + 1) / 2;
  239.  
  240.         // ¾ئہجؤـہ» ±×¸³´د´ظ.
  241.         dc.DrawIcon(x, y, m_hIcon);
  242.     }
  243.     else
  244.     {
  245.         CDialog::OnPaint();
  246.     }
  247. }
  248.  
  249. // »ç؟ëہع°، أض¼زب*µب أ¢ہ» ²ô´آ µ؟¾ب؟، ؤ؟¼*°، ا¥½أµاµµ·د ½أ½؛إغ؟،¼*
  250. //  ہج اش¼ِ¸¦ ب£أâاص´د´ظ.
  251. HCURSOR CFTDI_loadDlg::OnQueryDragIcon()
  252. {
  253.     return static_cast<HCURSOR>(m_hIcon);
  254. }
  255.  
  256. //////////////////////////////////////////////////////////////////////////////////////////////
  257. //TEXT OUT MESSAGE TO CSTATIC
  258. //////////////////////////////////////////////////////////////////////////////////////////////
  259.  
  260.  
  261. void PutStaticMessage(int DefinedMSG)
  262. {
  263.     CString StrCode;
  264.     CString StrCodeWithID;
  265.  
  266.     StrCode = (CString)DialogMessageList[DefinedMSG];
  267.  
  268.     CStatic *pCStatic;
  269.     CListBox *pCListBox;
  270.  
  271.     CWinApp *pWinApp = AfxGetApp(); 
  272.     CWnd *pCWnd = pWinApp->GetMainWnd();
  273.  
  274.     pCStatic = (CStatic *)pCWnd->GetDlgItem(IDC_MESSAGE_STATIC);
  275.     pCListBox = (CListBox *)pCWnd->GetDlgItem(ID_STATUS_LST);
  276.  
  277.     if(DefinedMSG == MESSAGE_IS_NOT_REGISTERED || DefinedMSG == MESSAGE_IS_REGISTERED
  278.         || DefinedMSG == MESSAGE_IS_NOT_CERTIFICATED || DefinedMSG == MESSAGE_IS_CERTIFICATED)
  279.     {
  280.         char    Temp[256];
  281.         char    Temp2[256];
  282.         int        TempLength;
  283.         int        TempLength2;
  284.         unsigned char ReturnID[ID_STR_LENGTH_SIZE];
  285.  
  286.         memset(ReturnID,'\0',ID_STR_LENGTH_SIZE);
  287.         memcpy(ReturnID,RxData.RxDataID,sizeof(RxData.RxDataID));
  288.         //ReturnID[strlen((const char *)RxData.RxDataID)+1] = '\0';
  289.         //to make ReturnID STRING type, adding NULL to end of string
  290.  
  291.         TempLength = 9 + strlen((const char *)ReturnID)+strlen(DialogMessageList[DefinedMSG]);
  292.         TempLength2 = strlen(DialogMessageList[DefinedMSG]);
  293.         //////memory reset
  294.         memset(Temp,NULL,TempLength);
  295.         memset(Temp2,NULL,TempLength2);
  296.         //
  297.         memcpy(Temp2,&DialogMessageList[DefinedMSG],TempLength2);
  298.         Temp2[strlen(DialogMessageList[DefinedMSG])] = '\0';
  299.         sprintf(Temp,"'%s' is %s",(const char *)ReturnID,Temp2);
  300.  
  301.         StrCodeWithID = (LPCSTR)(LPSTR)Temp;
  302.         pCStatic->SetWindowText(StrCodeWithID);
  303.     }
  304.     else
  305.     {
  306.         pCStatic->SetWindowText(StrCode);
  307.         if(DefinedMSG == MESSAGE_DATABASE_EMPTY)
  308.         {
  309.             pCListBox->ResetContent();
  310.         }    
  311.     }
  312. }
  313.  
  314. //////////////////////////////////////////////////////////////////////////////////////////////
  315. //TEXT OUT ID LIST TO CLISTBOX
  316. //////////////////////////////////////////////////////////////////////////////////////////////
  317.  
  318. void PutList()
  319. {
  320.     USES_CONVERSION;
  321.     LPWSTR Target;
  322.  
  323.     CListBox *pCListBox;
  324.     unsigned char IDstr[ID_STR_LENGTH_SIZE];
  325.  
  326.     CWinApp *p_WinApp = AfxGetApp();
  327.     CWnd *pCWnd = p_WinApp->GetMainWnd();
  328.     pCListBox = (CListBox *)pCWnd->GetDlgItem(ID_STATUS_LST);
  329.  
  330.     pCListBox->ResetContent();
  331.  
  332.     for(int i=0;i<RxData.RxDataIDTotalLength;i++)
  333.     {
  334.         memset(IDstr, 0x00, ID_STR_LENGTH_SIZE);
  335.         memcpy(IDstr, &RxData.RxDataIDTotal[(i * ID_LENGTH_SIZE)], ID_LENGTH_SIZE);
  336.  
  337.         Target = A2W ((char *)IDstr);
  338.         pCListBox->AddString(Target);
  339.     }
  340.  
  341.     PutStaticMessage(MESSAGE_LIST_DONE);
  342. }
  343.  
  344. //////////////////////////////////////////////////////////////////////////////////////////////
  345. //DATA INSERT TO "GLOBAL DATA STRUCTURE" FROM DLL
  346. //////////////////////////////////////////////////////////////////////////////////////////////
  347. void DllUsbCheckCallBack(bool USBStatus)
  348. {
  349.     switch(USBStatus)
  350.     {
  351.     case USB_NOT_FOUND:
  352.         MyAfxMessageBox("USB NOT FOUND");
  353.  
  354.         g_USBStatus = USB_NOT_FOUND;
  355.         PutStaticMessage(MESSAGE_USB_NOT_FOUND);
  356.         UsbFoundMessageOutOnce = false;
  357.         g_USBStatusMessageOutOnce = true;
  358.         break;
  359.  
  360.     case USB_FOUND:
  361.         g_USBStatus = USB_FOUND;
  362.         if(g_USBStatusMessageOutOnce)
  363.         {
  364.             if(!UsbFoundMessageOutOnce)
  365.             {
  366.                 PutStaticMessage(MSEEAGE_USB_FOUND);
  367.                 UsbFoundMessageOutOnce = true;
  368.             }
  369.         }
  370.         break;
  371.     }
  372. }
  373.  
  374. void RxBufferReturnDataCallBack(ReturnData *RData)
  375. {
  376.     if(g_USBStatus == USB_NOT_FOUND)return;
  377.  
  378.     //copy data from DLL to local temp RD
  379.     ReturnData RD;
  380.     memcpy(&RD,RData,sizeof(RD));
  381.  
  382.     //copy RD to global RxData
  383.     //id data
  384.     memcpy(&RxData.RxDataIDTotal,&RD.RxDataIDTotal,sizeof(RD.RxDataIDTotal));
  385.     //id name
  386.     memcpy(&RxData.RxDataID,&RD.RxDataID,ID_LENGTH_SIZE);
  387.     //id length
  388.     RxData.RxDataIDTotalLength = RD.RxDataIDTotalLength;
  389.     //return code
  390.     RxData.RxCode = RD.RxCode;
  391.     //template length
  392.     RxData.RxTemplateLength = RD.RxTemplateLength;
  393.     //template data
  394.     memcpy(&RxData.RxTemplateData,&RD.RxTemplateData,RD.RxTemplateLength);
  395.  
  396.     if(RxData.RxCode == 0x1a)
  397.     {
  398.         g_USBStatus = USB_FOUND;
  399.     }
  400.     else if(RxData.RxCode != 0x00)
  401.     {
  402.         ResultMessageTextOut(RxData.RxCode);
  403.  
  404.         switch(RxData.RxCode)
  405.         {
  406.         case ID_LIST_GET:
  407.             PutList();
  408.             break;
  409.  
  410.         case GET_TEMPLATE_RETRIEVAL_COMPLETE:
  411.             SaveTemplate(RxData);
  412.             break;
  413.         }
  414.     }
  415. }
  416.  
  417. //////////////////////////////////////////////////////////////////////////////////////////////
  418. //ALL BUTTON EVENT
  419. //////////////////////////////////////////////////////////////////////////////////////////////
  420.  
  421. void CFTDI_loadDlg::OnBnClickedRegistrationBtn()
  422. {
  423.     if(g_USBStatus == USB_FOUND)
  424.     {
  425.         GetID(g_ID);
  426.  
  427.         if(strlen(g_ID) == 0)
  428.         {
  429.             PutStaticMessage(MESSAGE_ID_NOT_INSERTED);
  430.         }
  431.         else if(strlen(g_ID) > 0)
  432.         {
  433.             if(strlen(g_ID) >20)
  434.             {
  435.                 PutStaticMessage(MESSAGE_ID_LENGTH_EXCEEDED);
  436.             }
  437.             else
  438.             {
  439.                 PutStaticMessage(MESSAGE_IS_REGISTERING);
  440.                 IrisRegister(&RxBufferReturnDataCallBack,g_ID);
  441.             }
  442.         }
  443.     }
  444.     else
  445.     {
  446.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  447.     }
  448. }
  449.  
  450. void CFTDI_loadDlg::OnBnClickedCertificationBtn()
  451. {
  452.     if(g_USBStatus == USB_FOUND)
  453.     {
  454.         GetID(g_ID);
  455.         IrisCertify(&RxBufferReturnDataCallBack,g_ID);
  456.     }
  457.     else
  458.     {
  459.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  460.     }
  461. }
  462.  
  463. void CFTDI_loadDlg::OnBnClickedSaveBtn()
  464. {
  465.     if(g_USBStatus == USB_FOUND)
  466.     {
  467.         IrisIDSave(&RxBufferReturnDataCallBack);
  468.     }
  469.     else
  470.     {
  471.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  472.     }
  473. }
  474.  
  475. void CFTDI_loadDlg::OnBnClickedCancelBtn()
  476. {
  477.     g_Cancelation = true;    
  478.  
  479.     if(g_USBStatus == USB_FOUND)
  480.     {
  481.         IrisCancel(&RxBufferReturnDataCallBack);
  482.     }
  483.     else
  484.     {
  485.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  486.     }    
  487. }
  488.  
  489. void CFTDI_loadDlg::OnBnClickedListBtn()
  490. {
  491.     if(g_USBStatus == USB_FOUND)
  492.     {
  493.         IrisGetIDList(&RxBufferReturnDataCallBack);
  494.     }
  495.     else
  496.     {
  497.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");    
  498.     }
  499. }
  500.  
  501. void CFTDI_loadDlg::OnBnClickedDeleteBtn()
  502. {
  503.     int rMsg = 0;
  504.  
  505.     /*CString Msg;
  506.     CString Msg2*/;
  507.     USES_CONVERSION;
  508.     LPWSTR Msg;
  509.     LPWSTR Msg2;
  510.  
  511.     memset(&g_ID,0x00,sizeof(g_ID));
  512.  
  513.     char    MsgTemp[256];
  514.     char    MsgTemp2[256];
  515.  
  516.     GetID(g_ID);
  517.  
  518.     sprintf(MsgTemp,"Would like to delete '%s'?",g_ID);
  519.     sprintf(MsgTemp2,"Without ID, Would like to delete all ID?");
  520.  
  521.     //Msg = (LPCSTR)(LPSTR)MsgTemp;
  522.     //Msg2 = (LPCSTR)(LPSTR)MsgTemp2;
  523.     Msg = A2W ((char *)MsgTemp);
  524.     Msg2 = A2W ((char *)MsgTemp2); 
  525.  
  526.     if(g_USBStatus == USB_FOUND)
  527.     {
  528.         if(strlen(g_ID) > 0)
  529.         {
  530.             rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_YESNO);
  531.  
  532.             if (rMsg == IDYES)
  533.             {
  534.                 IrisIDDelete(&RxBufferReturnDataCallBack,g_ID);
  535.             }
  536.             else if(rMsg == IDNO)
  537.             {
  538.                 IrisCancel(&RxBufferReturnDataCallBack);
  539.                 MyAfxMessageBox("ID deletion canceled.");
  540.             }
  541.         }
  542.         else
  543.         {
  544.             rMsg = MessageBox(Msg2, NULL, MB_ICONWARNING | MB_YESNO);
  545.  
  546.             if (rMsg == IDYES)
  547.             {
  548.                 memset(g_ID,'\0',sizeof(g_ID));
  549.                 IrisIDDelete(&RxBufferReturnDataCallBack,g_ID);
  550.             }
  551.             else if(rMsg == IDNO)
  552.             {
  553.                 IrisCancel(&RxBufferReturnDataCallBack);
  554.                 MyAfxMessageBox("All ID deletion canceled");
  555.             }
  556.         }
  557.  
  558.         //IrisGetIDList(&RxBufferReturnDataCallBack);
  559.     }
  560.     else
  561.     {
  562.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  563.     }
  564. }
  565.  
  566. void CFTDI_loadDlg::OnBnClickedGetIrisBtn()
  567. {
  568.     if(g_USBStatus == USB_FOUND)
  569.     {
  570.         GetID(g_ID);
  571.         if(strlen(g_ID) > 0)
  572.         {
  573.             IrisGetTemplate(&RxBufferReturnDataCallBack,g_ID);    
  574.         }
  575.         else
  576.         {
  577.             MyAfxMessageBox("Please select ID list.");
  578.         }
  579.     }
  580.     else
  581.     {
  582.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  583.     }
  584. }
  585.  
  586. void CFTDI_loadDlg::OnBnClickedPutIrisBtn()
  587. {
  588.     if(g_USBStatus == USB_FOUND)
  589.     {
  590.         int rMsg = 0;
  591.  
  592.         //////////////////
  593.         //file open dialog
  594.  
  595.         //declare variable
  596.         char *sep = "\\";
  597.         char *token;
  598.         char temp[256];
  599.  
  600.         char *str = new char[256];
  601.         RtlZeroMemory(str, 256);
  602.  
  603.         OPENFILENAME ofn;
  604.         memset(&ofn,0,sizeof(OPENFILENAME));
  605.         ofn.lStructSize = sizeof(OPENFILENAME);
  606.         ofn.hwndOwner = this->m_hWnd;
  607.         ofn.lpstrFile = (LPWSTR)str;
  608.  
  609.         ofn.nMaxFile = 256;
  610.         ofn.lpstrTitle = L"Select Iris template file (*.bin) to identify your iris.";
  611.         ofn.lpstrFilter = L"Iris Template File (*.bin)\0*.bin\0";
  612.         GetOpenFileName(&ofn);
  613.  
  614.         //CString temp1;
  615.  
  616.         RtlZeroMemory(g_FilePath,256);
  617.         RtlZeroMemory(g_ID,256);
  618.  
  619.         WideCharToMultiByte(CP_ACP, 0, ofn.lpstrFile, -1, g_FilePath, 128, NULL, NULL);
  620.         token = strtok(g_FilePath,sep);
  621.         while(token)
  622.         {
  623.             RtlCopyMemory(temp,token,sizeof(g_ID));
  624.             token = strtok(NULL,sep);
  625.             if(token == NULL)
  626.             {
  627.                 break;
  628.             }
  629.         }
  630.  
  631.         for(int i=4;i<strlen(temp);i++)
  632.         {
  633.             if(temp[i] == '.')
  634.             {
  635.                 break;
  636.             }
  637.  
  638.             g_ID[i-4] = temp[i];
  639.  
  640.         }
  641.  
  642.         int ErrorCode;
  643.         ErrorCode = ReadTemplate(g_ID);
  644.         if(ErrorCode == 0)
  645.         {
  646.             PutStaticMessage(MESSAGE_TEMPLATE_ID_NOT_FOUND);
  647.         }
  648.         else
  649.         {
  650.             IrisPutTemplate(&RxBufferReturnDataCallBack,g_ID,&RxData);
  651.         }
  652.     }
  653.     else
  654.     {
  655.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  656.     }
  657. }
  658.  
  659. void CFTDI_loadDlg::OnBnClickedLampBtn()
  660. {
  661. }
  662.  
  663. void CFTDI_loadDlg::OnBnClickedCloseBtn()
  664. {
  665.     OnCancel();
  666. }
  667.  
  668. //////////////////////////////////////////////////////////////////////////////////////////////
  669. //CLISTBOX EVENT WHEN CLICK ID
  670. //////////////////////////////////////////////////////////////////////////////////////////////
  671.  
  672. void CFTDI_loadDlg::OnLbnSelchangeStatusLst()
  673. {
  674.     int         sel = 0;
  675.     CString        StrBuffer;
  676.     CListBox    *pCListBox;
  677.     CEdit        *pCEdit;
  678.  
  679.     pCListBox    = (CListBox *)GetDlgItem(ID_STATUS_LST);
  680.     pCEdit        = (CEdit *)GetDlgItem(IDC_ID_EDT);
  681.  
  682.     int nIndex = pCListBox->GetCurSel();
  683.     int nCount = pCListBox->GetCount();
  684.     if ((nIndex != LB_ERR) && (nCount > 0))
  685.     {
  686.         sel = pCListBox->GetCurSel();
  687.         pCListBox->GetText(sel, StrBuffer);
  688.         pCEdit->SetWindowText(StrBuffer);
  689.     }
  690. }
  691.  
  692. //////////////////////////////////////////////////////////////////////////////////////////////
  693. //GET ID FROM CEDIT
  694. //////////////////////////////////////////////////////////////////////////////////////////////
  695.  
  696. void GetID(char *g_ID)
  697. {
  698.     CString        StrID;
  699.     CString        Msg;
  700.     char        MsgTemp[256];
  701.     CEdit        *pCEdt;
  702.  
  703.     CWinApp        *p_WinApp = AfxGetApp();
  704.     CWnd        *pCWnd = p_WinApp->GetMainWnd();
  705.     pCEdt = (CEdit *)pCWnd->GetDlgItem(IDC_ID_EDT);
  706.  
  707.     pCEdt->GetWindowText(StrID);
  708.  
  709.     sprintf(g_ID, "%s", CT2A(StrID));
  710. }
  711.  
  712. //////////////////////////////////////////////////////////////////////////////////////////////
  713. //MAPPING "RETURN CODE" TO "RESULT MASSAGE"
  714. //////////////////////////////////////////////////////////////////////////////////////////////
  715.  
  716. void ResultMessageTextOut(ReturnCode DlgRCode)
  717. {
  718.     switch(DlgRCode)
  719.     {
  720.     case REGISTRATION_FAIL : //registration failure
  721.  
  722.         PutStaticMessage(MESSAGE_IS_NOT_REGISTERED);
  723.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_NOT_REGISTERED]);
  724.         break;
  725.  
  726.     case IDENTIFICATION_FAIL : //certification failure
  727.         PutStaticMessage(MESSAGE_IS_NOT_CERTIFICATED);
  728.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_NOT_CERTIFICATED]);
  729.         break;
  730.  
  731.     case DELETION_FAIL : //deletion failure "id not found"
  732.         PutStaticMessage(MESSAGE_DELETE_FAIL);
  733.         //AfxMessageBox(DialogMessageList[MESSAGE_DELETE_FAIL]);
  734.         break;
  735.  
  736.     case ID_LIST_GET : //receive ID length
  737.         PutStaticMessage(MESSAGE_LIST);
  738.         //AfxMessageBox(DialogMessageList[MESSAGE_LIST]);
  739.         break;
  740.  
  741.         //working
  742.     case COMMON_VERSION_DISPLAY : //version
  743.         PutStaticMessage(MESSAGE_LIST);
  744.         //AfxMessageBox(DialogMessageList[MESSAGE_LIST]);
  745.         break;
  746.  
  747.     case COMMON_CANCELATION : //cancel
  748.         PutStaticMessage(MESSAGE_CANCEL);
  749.         //AfxMessageBox(DialogMessageList[MESSAGE_CANCEL]);
  750.         break;
  751.  
  752.     case REGISTERARION_NO_IRIS_FRAME : //no frame captured
  753.  
  754.         PutStaticMessage(MESSAGE_REGI_NO_FRAME_CAPTURED);
  755.         //AfxMessageBox(DialogMessageList[MESSAGE_NO_FRAME_CAPTURED]);
  756.         break;
  757.  
  758.     case IDENTIFICATION_NO_IRIS_FRAME : //no frame captured
  759.         PutStaticMessage(MESSAGE_CERT_NOT_ENOUGH_FRAME);
  760.         //AfxMessageBox(DialogMessageList[MESSAGE_CERT_NOT_ENOUGH_FRAME]);
  761.         break;
  762.  
  763.     case IDENTIFICATION_NONE_IN_DB : //data base empty
  764.         PutStaticMessage(MESSAGE_DATABASE_EMPTY);
  765.         //AfxMessageBox(DialogMessageList[MESSAGE_DATABASE_EMPTY]);
  766.         break;
  767.  
  768.     case IDENTIFICATION_NO_ID_IN_DB : //data base empty
  769.         PutStaticMessage(MESSAGE_DATABASE_EMPTY);
  770.         //AfxMessageBox(DialogMessageList[MESSAGE_DATABASE_EMPTY]);
  771.         break;
  772.  
  773.     case REGISTRATION_MODULE_DB_OVER_FLOW : //data base full
  774.  
  775.         PutStaticMessage(MESSAGE_DATABASE_FULL);
  776.         //AfxMessageBox(DialogMessageList[MESSAGE_DATABASE_FULL]);
  777.         break;
  778.  
  779.     case REGISTRATION_BAD_OR_INSUFFICENT_IRIS_FRAME : //not enough frame for registration
  780.  
  781.         PutStaticMessage(MESSAGE_REGI_NOT_ENOUGH_FRAME);
  782.         //AfxMessageBox(DialogMessageList[MESSAGE_REGI_NOT_ENOUGH_FRAME]);
  783.         break;
  784.  
  785.     case SAVE_FAIL : //save failure
  786.         PutStaticMessage(MESSAGE_IS_NOT_SAVED);
  787.         ///AfxMessageBox(DialogMessageList[MESSAGE_IS_NOT_SAVED]);
  788.         break;
  789.  
  790.     case COMMON_SYSTEM_INIT : //system initialization
  791.         PutStaticMessage(MESSAGE_COMMON_SYSTEM_INIT);
  792.         //AfxMessageBox(DialogMessageList[MESSAGE_COMMON_SYSTEM_INIT]);
  793.         break;
  794.  
  795.     case COMMON_TIMEOVER : //time over
  796.         PutStaticMessage(MESSAGE_TIME_OVER);
  797.         //AfxMessageBox(DialogMessageList[MESSAGE_TIME_OVER]);
  798.         break;
  799.  
  800.     case COMMON_CHECKSUM_ERROR : //checksum ERROR
  801.         PutStaticMessage(MESSAGE_COMMON_CHECKSUM_ERROR);
  802.         //AfxMessageBox(DialogMessageList[MESSAGE_COMMON_CHECKSUM_ERROR]);
  803.         break;
  804.  
  805.     case GET_TEMPLATE_RETRIEVAL_START : //transmission start
  806.         PutStaticMessage(MESSAGE_PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START);
  807.         //AfxMessageBox(DialogMessageList[MESSAGE_PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START]);
  808.         break;
  809.  
  810.     case GET_TEMPLATE_RETRIEVAL_COMPLETE : //transmission complete
  811.         PutStaticMessage(MESSAGE_REGIST_CODE_DOWNLOAD);
  812.         //AfxMessageBox(DialogMessageList[MESSAGE_REGIST_CODE_DOWNLOAD]);
  813.         break;
  814.  
  815.     case PUT_TEMPLATE_FILE_FORMAT_ERROR : //checksum ERROR
  816.         PutStaticMessage(MESSAGE_COMMON_CHECKSUM_ERROR);
  817.         //AfxMessageBox(DialogMessageList[MESSAGE_COMMON_CHECKSUM_ERROR]);
  818.         break;
  819.  
  820.     case PUT_TEMPLATE_DB_OVER_FLOW : //db over flow (download)
  821.         PutStaticMessage(MESSAGE_DATABASE_FULL);
  822.         //AfxMessageBox(DialogMessageList[MESSAGE_DATABASE_FULL]);
  823.         break;
  824.  
  825.     case PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START : //ready to start
  826.         PutStaticMessage(MESSAGE_PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START);
  827.         //AfxMessageBox(DialogMessageList[MESSAGE_PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START]);
  828.         break;
  829.  
  830.     case REGISTRATION_VIDEO_MODE :
  831.  
  832.         PutStaticMessage(MESSAGE_PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START);
  833.         //AfxMessageBox(DialogMessageList[MESSAGE_DATABASE_FULL]);
  834.         break;
  835.  
  836.     case REGISTRATION_SUCCESS : //registration success
  837.  
  838.         PutStaticMessage(MESSAGE_IS_REGISTERED);
  839.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_REGISTERED]);
  840.         break;
  841.  
  842.     case IDENTIFICATION_SUCCESS : //identification success
  843.         PutStaticMessage(MESSAGE_IS_CERTIFICATED);
  844.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_CERTIFICATED]);
  845.         break;
  846.  
  847.         //working
  848.     case DELETION_SUCCESS : //delete all or one
  849.         PutStaticMessage(MESSAGE_IS_DELETED);
  850.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_DELETED]);
  851.         break;
  852.  
  853.     case SAVE_SUCCESS : //save success
  854.         PutStaticMessage(MESSAGE_IS_SAVED);
  855.         //AfxMessageBox(DialogMessageList[MESSAGE_IS_SAVED]);
  856.         break;
  857.     }
  858. }
  859.  
  860. int ReadTemplate(char *g_ID)
  861. {
  862.     if(g_USBStatus == USB_NOT_FOUND)return 0;
  863.  
  864.     HANDLE    h_Template;
  865.     DWORD    dwBytesRead = 0;
  866.  
  867.     memset(&FileName[0],0x00,256);
  868.  
  869.     sprintf((char *)FileName,"REG_%s.bin",g_ID);
  870.  
  871.     USES_CONVERSION;
  872.     LPWSTR FName;
  873.     FName = A2W((LPCSTR)FileName);
  874.  
  875.     h_Template = CreateFile(FName,               // file to open
  876.         GENERIC_READ,          // open for reading
  877.         FILE_SHARE_READ,       // share for reading
  878.         NULL,                  // default security
  879.         OPEN_EXISTING,         // existing file only
  880.         FILE_ATTRIBUTE_NORMAL, // normal file
  881.         NULL);                 // no attribute template
  882.  
  883.     if (h_Template == INVALID_HANDLE_VALUE) 
  884.     { 
  885.         return 0; 
  886.     }
  887.  
  888.     if( FALSE == ReadFile(h_Template, ReadBuffer, MAX_SIZE, &dwBytesRead, NULL) )
  889.     {
  890.         CloseHandle(h_Template);
  891.         return 0;
  892.     }
  893.  
  894.     if (dwBytesRead > 0 || dwBytesRead <= MAX_SIZE)
  895.     {
  896.         ReadBuffer[dwBytesRead]='\0';
  897.         //printf("Data read from %s",g_ID);
  898.     }
  899.     else if (dwBytesRead == 0)
  900.     {
  901.         //printf("No data read from file %s\n");
  902.         return 0;
  903.     }
  904.     else
  905.     {
  906.         //printf("\n ** Unexpected value for dwBytesRead ** \n");
  907.         return 0;
  908.     }
  909.  
  910.     unsigned char DllInfo[21];
  911.     memset(DllInfo,0x00,21);
  912.     memcpy(DllInfo, &ReadBuffer[0], 20);
  913.     memcpy(&RxData.RxTemplateData,&ReadBuffer[40],dwBytesRead-40);
  914.     RxData.RxTemplateLength = dwBytesRead;
  915.  
  916.     CloseHandle(h_Template);
  917.     return 1;
  918. }
  919.  
  920. int SaveTemplate(ReturnData RxData)
  921. {
  922.     //write file
  923.     HANDLE h_Template;
  924.  
  925.     unsigned char HeaderTemplate[MAX_TEMPLATE_SIZE];
  926.     unsigned char DllInfo[21] = "QIRIBIOM60622-WINWIN";
  927.     DWORD dwBytesToWrite = (DWORD)(RxData.RxTemplateLength+40); //fixed header size : 40
  928.  
  929.     ////
  930.     //DWORD dwBytesToWrite = (DWORD)RxData.RxTemplateLength;
  931.     DWORD dwBytesWritten = 0;
  932.     BOOL bErrorFlag = FALSE;
  933.     unsigned char FileName[256];
  934.     memset(&FileName[0],0x00,256);
  935.  
  936.     sprintf((char *)FileName,"REG_%s.bin",RxData.RxDataID);
  937.     ////
  938.     memset(&HeaderTemplate[0],0x00,MAX_TEMPLATE_SIZE);
  939.     memcpy(HeaderTemplate, DllInfo, 20);
  940.     memcpy(&HeaderTemplate[20], RxData.RxDataID, 20);
  941.     memcpy(&HeaderTemplate[40], RxData.RxTemplateData, RxData.RxTemplateLength);
  942.  
  943.     USES_CONVERSION;
  944.     LPWSTR FName;
  945.     FName = A2W((LPCSTR)FileName);
  946.  
  947.     h_Template = CreateFile(FName,                // name of the write
  948.         GENERIC_WRITE,          // open for writing
  949.         0,                      // do not share
  950.         NULL,                   // default security
  951.         CREATE_NEW,             // create new file only
  952.         FILE_ATTRIBUTE_NORMAL,  // normal file
  953.         NULL);                  // no attribute template
  954.  
  955.     if (h_Template == INVALID_HANDLE_VALUE) 
  956.     { 
  957.         return 0;
  958.     }
  959.  
  960.     bErrorFlag = WriteFile( 
  961.         h_Template,           // open file handle
  962.         //&RxData.RxTemplateData,      // start of data to write
  963.         &HeaderTemplate[0],
  964.         dwBytesToWrite,  // number of bytes to write
  965.         &dwBytesWritten, // number of bytes that were written
  966.         NULL);            // no overlapped structure
  967.  
  968.     if (FALSE == bErrorFlag)
  969.     {
  970.         //printf("Terminal failure: Unable to write to file.\n");
  971.     }
  972.     else
  973.     {
  974.         if (dwBytesWritten != dwBytesToWrite)
  975.         {
  976.             //printf("Error: dwBytesWritten != dwBytesToWrite\n");
  977.         }
  978.         else
  979.         {
  980.             //printf("Wrote file successfully.\n");
  981.         }
  982.     }
  983.  
  984.     CloseHandle(h_Template);
  985.     return 1;
  986. }
  987.  
  988. void MemoryDumpData(ReturnData *Src, ReturnData *Dst)
  989. {
  990.     Src->RxTemplateLength = Dst->RxTemplateLength;
  991.     ////memory reset
  992.     memset(&Src->RxTemplateData,0x00,Src->RxTemplateLength);
  993.     ////copy TX buffer
  994.     memcpy(&Src->RxTemplateData,&Dst->RxTemplateData,Dst->RxTemplateLength);
  995. }
  996.  
  997. //////////////////////////////////////////////////////////////////////////////////////////////
  998. //MAKE LOG FILE TO DEBUG
  999. //////////////////////////////////////////////////////////////////////////////////////////////
  1000. static void WriteLog(const char* msg) {
  1001.     USES_CONVERSION;
  1002.     HANDLE h = CreateFile(A2W(LOGFILE_PATH), GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0);
  1003.     if (INVALID_HANDLE_VALUE != h) {
  1004.         if (INVALID_SET_FILE_POINTER != SetFilePointer(h, 0, 0, FILE_END)) {
  1005.             DWORD cb = strlen(msg) * sizeof *msg;
  1006.             WriteFile(h, msg, cb, &cb, 0);
  1007.         }
  1008.         CloseHandle(h);
  1009.     }
  1010. }
  1011.  
  1012. //////////////////////////////////////////////////////////////////////////////////////////////
  1013. //MAKE LOG FILE TO DEBUG
  1014. //////////////////////////////////////////////////////////////////////////////////////////////
  1015.  
  1016. void MyAfxMessageBox( char* str )
  1017. {
  1018.     //if ( g_MyMsg )
  1019.     //    AfxMessageBox( CString(str));
  1020.  
  1021. #ifndef  API_DEBUG
  1022.     WriteLog(str);
  1023.     WriteLog((const char *)"\n");
  1024. #endif
  1025. }
  1026.  
  1027.  
  1028. //////////////////////////////////////////////////////////////////////////////////////////////////
  1029. //
  1030. //CHAIN-COMMAND FUNCTION, CHAIN-COMMAND RECIEVE CALLBACK FUNCTION, THREAD FUNCTION TO HANDLE EVENT
  1031. //
  1032. //////////////////////////////////////////////////////////////////////////////////////////////////
  1033.  
  1034. void CFTDI_loadDlg::OnBnClickedRegProcessBtn()
  1035. {
  1036.     Sleep(300);
  1037.  
  1038.     if(g_USBStatus == USB_FOUND)
  1039.     {
  1040.         GetID(g_ID);
  1041.  
  1042.         int rMsg = 0;
  1043.  
  1044.         if(strlen(g_ID) == 0)
  1045.         {
  1046.             PutStaticMessage(MESSAGE_ID_NOT_INSERTED);
  1047.         }
  1048.         else if(strlen(g_ID) > 0)
  1049.         {
  1050.             if(strlen(g_ID) >20)
  1051.             {
  1052.                 PutStaticMessage(MESSAGE_ID_LENGTH_EXCEEDED);
  1053.             }
  1054.             else
  1055.             {
  1056.                 PutStaticMessage(MESSAGE_IS_REGISTERING);
  1057.  
  1058.                 //get button handle
  1059.                 ////////////////////////////////////////////////////////////
  1060.                 ////2010.03.19 BUTTON DISABLE
  1061.                 ////////////////////////////////////////////////////////////
  1062.                 CButton *pCButton;
  1063.                 CWinApp *pWinApp = AfxGetApp(); 
  1064.                 CWnd *pCWnd = pWinApp->GetMainWnd();
  1065.                 pCButton = (CButton *)pCWnd->GetDlgItem(IDC_REG_PROCESS_BTN);
  1066.  
  1067.                 pCButton->EnableWindow(FALSE);
  1068.                                                                         ////
  1069.                 ////////////////////////////////////////////////////////////
  1070.  
  1071.  
  1072.  
  1073.  
  1074.                 ////////////////////////////////////////////////////////////
  1075.                 ////2010.03.19 DELETE ALL ID FROM MODULE
  1076.                 ////////////////////////////////////////////////////////////
  1077.                 memset(null_ID,'\0',sizeof(null_ID));
  1078.  
  1079.                 if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,null_ID);
  1080.                 //else return;
  1081.                 g_WaitForSingleObjectStart = true;
  1082.                 g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,5000);
  1083.                                                                         ////
  1084.                 ////////////////////////////////////////////////////////////
  1085.  
  1086.  
  1087.  
  1088.  
  1089.                 LPWSTR Msg = L"Please look at the mirror for registration. (keep 10 Cm distance) ";
  1090.  
  1091.                 rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1092.  
  1093.                 if (rMsg == IDOK)
  1094.                 {
  1095.                     MyAfxMessageBox("Reg start");
  1096.  
  1097.                     if(g_USBStatus == USB_FOUND)IrisRegister(&RxBufferReturnDataCallBackEx,g_ID);
  1098.                     else return;
  1099.  
  1100.                     g_WaitForSingleObjectStart = true;
  1101.                     WaitForSingleObject(hEvent,15000);
  1102.  
  1103.                     //first registration success
  1104.                     if(RxData.RxCode != REGISTRATION_SUCCESS)
  1105.                     {
  1106.                         ////////////////////////////////////////////////////////////
  1107.                         ////2010.03.19 IF-NOT REGISTERED, DELETE ID FROM MODULE
  1108.                         ////////////////////////////////////////////////////////////
  1109.  
  1110.                         PutStaticMessage(MESSAGE_IS_NOT_REGISTERED);
  1111.                         pCButton->EnableWindow(TRUE);
  1112.                         if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1113.                         g_WaitForSingleObjectStart = true;
  1114.                         g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,5000);
  1115.                         return;
  1116.                                                                                 ////
  1117.                         ////////////////////////////////////////////////////////////
  1118.                     }
  1119.  
  1120.                     LPWSTR Msg = L"Please register once more.";
  1121.                     rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1122.                     if (rMsg == IDOK)
  1123.                     {
  1124.  
  1125.                         if(g_USBStatus == USB_FOUND)IrisRegister(&RxBufferReturnDataCallBackEx,g_ID);
  1126.                         //else return;
  1127.  
  1128.                         g_WaitForSingleObjectStart = true;
  1129.                         WaitForSingleObject(hEvent,15000);
  1130.  
  1131.                         //second registration
  1132.                         if(RxData.RxCode != REGISTRATION_SUCCESS)
  1133.                         {
  1134.                             ////////////////////////////////////////////////////////////
  1135.                             ////2010.03.19 IF-NOT REGISTERED, DELETE ID FROM MODULE
  1136.                             ////////////////////////////////////////////////////////////
  1137.  
  1138.                             PutStaticMessage(MESSAGE_IS_NOT_REGISTERED);
  1139.                             pCButton->EnableWindow(TRUE);
  1140.                             if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1141.                             g_WaitForSingleObjectStart = true;
  1142.                             g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,5000);
  1143.                             return;
  1144.                                                                                     ////
  1145.                             ////////////////////////////////////////////////////////////
  1146.                         }
  1147.                         LPWSTR Msg = L"Successfully registered. Please look at the mirror for identification.";
  1148.  
  1149.                         rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1150.                         if (rMsg == IDOK)
  1151.                         {
  1152.                             //Sleep(2000);
  1153.  
  1154.                             if(g_USBStatus == USB_FOUND)IrisCertify(&RxBufferReturnDataCallBackEx,g_ID);
  1155.                             //else return;
  1156.  
  1157.                             g_WaitForSingleObjectStart = true;
  1158.                             WaitForSingleObject(hEvent,15000);
  1159.  
  1160.                             //certification success
  1161.                             if(RxData.RxCode != IDENTIFICATION_SUCCESS)
  1162.                             {
  1163.                                 ////////////////////////////////////////////////////////////
  1164.                                 ////2010.03.19 IF-NOT IDENTIFIED, DELETE ID FROM MODULE
  1165.                                 ////////////////////////////////////////////////////////////
  1166.  
  1167.                                 PutStaticMessage(MESSAGE_IS_NOT_REGISTERED);
  1168.                                 pCButton->EnableWindow(TRUE);
  1169.                                 if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1170.                                 g_WaitForSingleObjectStart = true;
  1171.                                 g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,5000);
  1172.                                 return;
  1173.                                                                                         ////
  1174.                                 ////////////////////////////////////////////////////////////
  1175.                             }
  1176.                             //Sleep(2000);//sync. not required
  1177.  
  1178.                             IrisGetTemplate(&RxBufferReturnDataCallBackEx,g_ID);
  1179.  
  1180.                             g_WaitForSingleObjectStart = true;
  1181.                             WaitForSingleObject(hEvent,15000);
  1182.  
  1183.  
  1184.                             //get template success
  1185.                             if(RxData.RxCode != GET_TEMPLATE_RETRIEVAL_COMPLETE)
  1186.                             {
  1187.                                 ResultMessageTextOut(MESSAGE_IS_NOT_CERTIFICATED);
  1188.                                 pCButton->EnableWindow(TRUE);
  1189.                                 return;
  1190.                             }
  1191.  
  1192.                             if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1193.                             //else return;
  1194.  
  1195.                             g_WaitForSingleObjectStart = true;
  1196.                             g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,5000);
  1197.  
  1198.  
  1199.  
  1200.                             //deletion success
  1201.                             if(RxData.RxCode == DELETION_SUCCESS)
  1202.                             {
  1203.                                 LPWSTR Msg = L"Registration process was completed";
  1204.                                 PutStaticMessage(MESSAGE_IS_REGISTERED);
  1205.                                 rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1206.                                 ////////////////////////////////////////////////////////////
  1207.                                 ////2010.03.19 BUTTON ENABLE
  1208.                                 ////////////////////////////////////////////////////////////
  1209.                                 pCButton->EnableWindow(TRUE);
  1210.                                                                                         ////
  1211.                                 ////////////////////////////////////////////////////////////
  1212.                             }
  1213.                             else
  1214.                             {
  1215.                                 if(RxData.RxCode != DELETION_SUCCESS)
  1216.                                 {
  1217.                                     //memcpy(&RxData.RxDataID[0],&g_ID[0],ID_LENGTH_SIZE);
  1218.                                     ResultMessageTextOut(MESSAGE_IS_NOT_REGISTERED);
  1219.                                     ////////////////////////////////////////////////////////////
  1220.                                     ////2010.03.19 BUTTON ENABLE
  1221.                                     ////////////////////////////////////////////////////////////
  1222.                                     pCButton->EnableWindow(TRUE);
  1223.                                     ////
  1224.                                     ////////////////////////////////////////////////////////////
  1225.                                     return;
  1226.                                 }
  1227.                             }
  1228.                         }
  1229.                     }
  1230.                 }
  1231.             }
  1232.         }
  1233.     }
  1234.     else
  1235.     {
  1236.     MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  1237.     }
  1238.  
  1239. }
  1240.  
  1241. void CFTDI_loadDlg::OnBnClickedIDProcessBtn()
  1242. {
  1243.     if(g_USBStatus == USB_FOUND)
  1244.     {
  1245.         int rMsg = 0;
  1246.  
  1247.         //////////////////
  1248.         //file open dialog
  1249.  
  1250.         //declare variable
  1251.         char *sep = "\\";
  1252.         char *token;
  1253.         char temp[256];
  1254.  
  1255.         char *str = new char[256];
  1256.         RtlZeroMemory(str, 256);
  1257.  
  1258.         OPENFILENAME ofn;
  1259.         memset(&ofn,0,sizeof(OPENFILENAME));
  1260.         ofn.lStructSize = sizeof(OPENFILENAME);
  1261.         ofn.hwndOwner = this->m_hWnd;
  1262.         ofn.lpstrFile = (LPWSTR)str;
  1263.  
  1264.         ofn.nMaxFile = 256;
  1265.         ofn.lpstrTitle = L"Select Iris template file (*.bin) to identify your iris.";
  1266.         ofn.lpstrFilter = L"Iris Template File (*.bin)\0*.bin\0";
  1267.         GetOpenFileName(&ofn);
  1268.  
  1269.         //CString temp1;
  1270.  
  1271.         RtlZeroMemory(g_FilePath,256);
  1272.         RtlZeroMemory(g_ID,256);
  1273.  
  1274.         WideCharToMultiByte(CP_ACP, 0, ofn.lpstrFile, -1, g_FilePath, 128, NULL, NULL);
  1275.         token = strtok(g_FilePath,sep);
  1276.         while(token)
  1277.         {
  1278.             RtlCopyMemory(temp,token,sizeof(g_ID));
  1279.             token = strtok(NULL,sep);
  1280.             if(token == NULL)
  1281.             {
  1282.                 break;
  1283.             }
  1284.         }
  1285.  
  1286.         for(int i=4;i<strlen(temp);i++)
  1287.         {
  1288.             if(temp[i] == '.')
  1289.             {
  1290.                 break;
  1291.             }
  1292.  
  1293.             g_ID[i-4] = temp[i];
  1294.  
  1295.         }
  1296.  
  1297.         g_ContinueCommnad = true;
  1298.  
  1299.         //get button handle
  1300.         ////////////////////////////////////////////////////////////
  1301.         ////2010.03.19 BUTTON DISABLE
  1302.         ////////////////////////////////////////////////////////////
  1303.         CButton *pCButton;
  1304.         CWinApp *pWinApp = AfxGetApp(); 
  1305.         CWnd *pCWnd = pWinApp->GetMainWnd();
  1306.         pCButton = (CButton *)pCWnd->GetDlgItem(IDC_CERT_PROCESS_BTN);
  1307.                                                                 ////
  1308.         ////////////////////////////////////////////////////////////
  1309.  
  1310.         //ADD MESSAGE TO RETURN_CODE.H & RETURN_CODE.CPP
  1311.         PutStaticMessage(MESSAGE_IS_CERTFYING);
  1312.  
  1313.         if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1314.         //else return;
  1315.         g_WaitForSingleObjectStart = true;
  1316.         g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,15000);
  1317.  
  1318.         int ErrorCode;
  1319.         ErrorCode = ReadTemplate(g_ID);
  1320.         if(ErrorCode == 0)
  1321.         {
  1322.             PutStaticMessage(MESSAGE_TEMPLATE_ID_NOT_FOUND);
  1323.             return;
  1324.         }
  1325.  
  1326.         //lock button
  1327.         pCButton->EnableWindow(FALSE);
  1328.  
  1329.         if(g_USBStatus == USB_FOUND)IrisPutTemplate(&RxBufferReturnDataCallBackEx,g_ID,&RxData);
  1330.         //else return;
  1331.  
  1332.         g_WaitForSingleObjectStart = true;
  1333.         g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,15000);
  1334.  
  1335.         if(RxData.RxCode != PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START)
  1336.         {
  1337.             PutStaticMessage(MESSAGE_COMMON_CHECKSUM_ERROR);
  1338.             //return;
  1339.         }
  1340.  
  1341.         LPWSTR Msg = L"Please look at the mirror for identification. (keep 10 Cm distance)";
  1342.         rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1343.         if (rMsg == IDOK)
  1344.         {
  1345.             if(g_USBStatus == USB_FOUND)IrisCertify(&RxBufferReturnDataCallBackEx,g_ID);
  1346.             //else return;
  1347.  
  1348.             g_WaitForSingleObjectStart = true;
  1349.             g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,15000);
  1350.  
  1351.             /////////////////////////////////////////////////////////////////////////////
  1352.             ////2010.03.19 IF-NOT CERTIFIED DELETE ID THEN PUT MESSAGE "NOT CERTIFICATED"
  1353.             //                IF CERTIFIED DELETE ID THEN PUT MESSAGE "CERTIFICATED"
  1354.             /////////////////////////////////////////////////////////////////////////////
  1355.  
  1356.  
  1357.             if(RxData.RxCode != IDENTIFICATION_SUCCESS)
  1358.             {
  1359.                 g_ContinueCommnad = false;
  1360.             }
  1361.  
  1362.             //Sleep(2000);
  1363.             if(g_USBStatus == USB_FOUND)IrisIDDelete(&RxBufferReturnDataCallBackEx,g_ID);
  1364.             //else return;
  1365.  
  1366.             g_WaitForSingleObjectStart = true;
  1367.             g_WaitForSingleObjectStatus = WaitForSingleObject(hEvent,15000);
  1368.  
  1369.  
  1370.             if(RxData.RxCode == DELETION_SUCCESS && g_ContinueCommnad == true)
  1371.             {
  1372.                 LPWSTR Msg = L"Identification process was completed.";
  1373.                 rMsg = MessageBox(Msg, NULL, MB_ICONWARNING | MB_OK);
  1374.                 PutStaticMessage(MESSAGE_IS_CERTIFICATED);
  1375.             }
  1376.             else
  1377.             {
  1378.                 ////////////////////////////////////////////////////////////////////////////////////////
  1379.                 //if not certified
  1380.                 ////////////////////////////////////////////////////////////////////////////////////////
  1381.                 memcpy(&RxData.RxDataID[0],&g_ID[0],ID_LENGTH_SIZE);
  1382.                 PutStaticMessage(MESSAGE_IS_NOT_CERTIFICATED);
  1383.             }
  1384.         }
  1385.         ////////////////////////////////////////////////////////////
  1386.         ////2010.03.19 BUTTON ENABLE
  1387.         ////////////////////////////////////////////////////////////
  1388.         pCButton->EnableWindow(TRUE);
  1389.                                                                 ////
  1390.         ////////////////////////////////////////////////////////////
  1391.     }
  1392.     else
  1393.     {
  1394.         MyAfxMessageBox("USB cable is unplugged. Command will not be executed");
  1395.     }
  1396.  
  1397. }
  1398.  
  1399. void RxBufferReturnDataCallBackEx(ReturnData *RData) //for chain command
  1400. {
  1401.     //copy data from DLL to local temp RD
  1402.     MyAfxMessageBox("--CALLBACK : DLL call");
  1403.     if(g_USBStatus == USB_NOT_FOUND)return;
  1404.  
  1405.     ReturnData RD;
  1406.     memcpy(&RD,RData,sizeof(RD));
  1407.  
  1408.     //copy RD to global RxData
  1409.     //id data
  1410.     memcpy(&RxData.RxDataIDTotal,&RD.RxDataIDTotal,sizeof(RD.RxDataIDTotal));
  1411.     //id name
  1412.     memcpy(&RxData.RxDataID,&RD.RxDataID,ID_LENGTH_SIZE);
  1413.     //id length
  1414.     RxData.RxDataIDTotalLength = RD.RxDataIDTotalLength;
  1415.     //return code
  1416.     RxData.RxCode = RD.RxCode;
  1417.     //template length
  1418.     RxData.RxTemplateLength = RD.RxTemplateLength;
  1419.     //template data
  1420.     memcpy(&RxData.RxTemplateData,&RD.RxTemplateData,RD.RxTemplateLength);
  1421.  
  1422.     if(RxData.RxCode == 0x1a)
  1423.     {
  1424.         g_USBStatus = USB_FOUND;
  1425.     }
  1426.     else if(RxData.RxCode != 0x00)
  1427.     {
  1428.         //set event for waiting for single object
  1429.         if(RxData.RxCode == REGISTRATION_SUCCESS || RxData.RxCode == REGISTRATION_FAIL ||RxData.RxCode == REGISTERARION_NO_IRIS_FRAME
  1430.             ||RxData.RxCode == REGISTRATION_BAD_OR_INSUFFICENT_IRIS_FRAME ||RxData.RxCode == REGISTRATION_MODULE_DB_OVER_FLOW
  1431.             ||RxData.RxCode == REGISTRATION_VIDEO_MODE ||RxData.RxCode == DELETION_SUCCESS ||RxData.RxCode == DELETION_FAIL
  1432.             ||RxData.RxCode == IDENTIFICATION_SUCCESS ||RxData.RxCode == IDENTIFICATION_FAIL ||RxData.RxCode == IDENTIFICATION_NO_IRIS_FRAME    
  1433.             ||RxData.RxCode == IDENTIFICATION_NO_ID_IN_DB ||RxData.RxCode == IDENTIFICATION_NONE_IN_DB ||RxData.RxCode == PUT_TEMPLATE_FILE_TRANSFER_READY_TO_START
  1434.             ||RxData.RxCode == PUT_TEMPLATE_DB_OVER_FLOW ||RxData.RxCode == PUT_TEMPLATE_FILE_FORMAT_ERROR ||RxData.RxCode == PUT_TEMPLATE_FILE_ALREADY_EXIST)
  1435.         {
  1436.             MyAfxMessageBox("--CALLBACK : branch");
  1437.  
  1438.             SetEvent(hEvent);
  1439.             g_hEvent = true;
  1440.         }
  1441.  
  1442.         if(RxData.RxCode == GET_TEMPLATE_RETRIEVAL_COMPLETE)
  1443.         {
  1444.             SetEvent(hEvent);
  1445.             g_hEvent = true;
  1446.             SaveTemplate(RxData);
  1447.         }
  1448.  
  1449.         if(g_hEvent == true)
  1450.         {
  1451.             g_hEvent = false;
  1452.             ResetEvent(hEvent);
  1453.         }
  1454.     }
  1455. }
  1456.  
  1457. UINT EventHandlerFunc(LPVOID lpParam)
  1458. {
  1459.     while(1)
  1460.     {
  1461.         Sleep(200);
  1462.  
  1463.         if((g_USBStatus == USB_NOT_FOUND && g_WaitForSingleObjectStart == true) || g_Cancelation == true)
  1464.         {
  1465.             g_WaitForSingleObjectStart = false;
  1466.             g_Cancelation = false;
  1467.  
  1468.             SetEvent(hEvent);
  1469.             g_hEvent = true;
  1470.  
  1471.             MyAfxMessageBox("SetEvent call");
  1472.  
  1473.             if(g_hEvent == true)
  1474.             {
  1475.                 g_hEvent = false;
  1476.                 ResetEvent(hEvent);
  1477.             }
  1478.         }
  1479.     }
  1480.  
  1481.     return 0;
  1482. }
  1483.  
  1484. void CFTDI_loadDlg::OnBnClickedPortOpenBtn()
  1485. {
  1486.     IrisModuleOpen();
  1487. }
  1488.  
  1489. void CFTDI_loadDlg::OnBnClickedPortCloseBtn()
  1490. {
  1491.     IrisModuleClose();
  1492. }
  1493.  
  1494.  
[ATTACH]IRIBIO_API_TEST SOURCE.zip[/ATTACH]
Aug 24 '10 #1
1 2370
weaknessforcats
9,208 Expert Mod 8TB
I think you will have considerable trouble converting MFC to C#.

May I suggest you start writing from scratch using the .NET Framework where all this MFC stuff has already been converted for you.
Aug 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: LornaJane | last post by:
I've not done very much Java before and now I'm working on a j2me application, however I think the trouble I have is generic java. I can compile, preverify and jar everything fine, but the...
0
by: Raghul | last post by:
Hi friends, I am creating a jabber client and a separate class for dialog is created,So when the roster name is clicked this dialog open and can continue chat.What I need is I am calling the same...
0
by: Jonah Olsson | last post by:
Dear Sirs, I'm looking for a way to define a class using an XML file. Since I'm building a Web Service to be used by several customers I want to be able to easily change the class below without...
6
by: Shibu | last post by:
Hi, Can anyone tell me how to create a DSN from asp.net.. Thanks Shibu
2
by: | last post by:
Today I learned that creating cookies inside of a custom class in ASP.NET 2.0 requires that you prefix it with HttpContext.Current..., e.g. : ...
8
by: KP | last post by:
How can we create class which other class can't be inherited or we can say how to protect class from inheritance ? ( e.g. final class in java, if a class is final in java, then this class can't be...
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
1
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi This is from within an EXE that actaully contains the class - No external assembly I would do Class1 myClass = new Class1(); Now I want
6
by: mlt | last post by:
I have the following class: class Test { public: Test() { a = 33; } private:
1
by: gundam | last post by:
I need to use Javascript in classic ASP for a project. However, I seem to have problem using javascript combined with ASP. Here are the questions: 1) ERROR to create class, see code below: <%@...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.