66#include < sys/time.h>
77#endif
88
9+ const int GetBarcodeFormatId (int iIndex)
10+ {
11+ switch (iIndex)
12+ {
13+ case 1 :
14+ return BF_ALL;
15+ case 2 :
16+ return BF_ONED;
17+ case 3 :
18+ return BF_QR_CODE;
19+ case 4 :
20+ return BF_CODE_39;
21+ case 5 :
22+ return BF_CODE_128;
23+ case 6 :
24+ return BF_CODE_93;
25+ case 7 :
26+ return BF_CODABAR;
27+ case 8 :
28+ return BF_ITF;
29+ case 9 :
30+ return BF_INDUSTRIAL_25;
31+ case 10 :
32+ return BF_EAN_13;
33+ case 11 :
34+ return BF_EAN_8;
35+ case 12 :
36+ return BF_UPC_A;
37+ case 13 :
38+ return BF_UPC_E;
39+ case 14 :
40+ return BF_PDF417;
41+ case 15 :
42+ return BF_DATAMATRIX;
43+ case 16 :
44+ return BF_AZTEC;
45+ case 17 :
46+ return BF_CODE_39_EXTENDED;
47+ case 18 :
48+ return BF_MAXICODE;
49+ case 19 :
50+ return BF_GS1_DATABAR;
51+ case 20 :
52+ return BF_PATCHCODE;
53+ case 21 :
54+ return BF_GS1_COMPOSITE;
55+ default :
56+ return -1 ;
57+ }
58+ }
59+
960void ToHexString (unsigned char * pSrc, int iLen, char * pDest)
1061{
1162 const char HEXCHARS[16 ] = { ' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' A' , ' B' , ' C' , ' D' , ' E' , ' F' };
@@ -15,11 +66,7 @@ void ToHexString(unsigned char* pSrc, int iLen, char* pDest)
1566
1667 for (i = 0 ; i < iLen; ++i)
1768 {
18- #if defined(WINDOWS)
19- sprintf_s (ptr, 4 , " %c%c " , HEXCHARS[ ( pSrc[i] & 0xF0 ) >> 4 ], HEXCHARS[ ( pSrc[i] & 0x0F ) >> 0 ]);
20- #else
2169 snprintf (ptr, 4 , " %c%c " , HEXCHARS[ ( pSrc[i] & 0xF0 ) >> 4 ], HEXCHARS[ ( pSrc[i] & 0x0F ) >> 0 ]);
22- #endif
2370 ptr += 3 ;
2471 }
2572}
@@ -39,13 +86,7 @@ int main(int argc, const char* argv[])
3986
4087 // Set license
4188 CBarcodeReader reader;
42- #if defined(WINDOWS)
43- const char * pszLicense = " t0068NQAAAGWe/zXkYmggvyFrd8PmfjplKakH67Upt9HvuRDIBAV6MZ4uODuL1ZUgSEAOygejsfwj6XRKI5iD1tLKZBRGo2c=" ;
44- #elif defined(LINUX)
45- const char * pszLicense = " t0068NQAAAIY/7KegDlZn7YiPdAj0cbA11n2CwuCEWnk2KYla55ozdfmoasjRIpHhl0EUZmko/zxfxFLH3FpLw694uihoCVM=" ;
46- #elif defined(MACOS)
47- const char * pszLicense = " t0068MgAAABIfuTSb0kBwnqpnVTBYgMZS0wAsmsmdeRPs5QylfKPQmoYYBhiNPClf1h7eTq/pnG1IVe11YB64srwtNzxTGLQ=" ;
48- #endif
89+ const char * pszLicense = " LICENSE-KEY" ;
4990 reader.InitLicense (pszLicense);
5091
5192 // Read barcode
@@ -63,45 +104,31 @@ int main(int argc, const char* argv[])
63104 #endif
64105
65106 // Output barcode result
66- #if defined(WINDOWS)
67- char *pszTemp = (char *)malloc (4096 );
68- #endif
69- if (iRet != DBR_OK && iRet != DBRERR_LICENSE_EXPIRED && iRet != DBRERR_QR_LICENSE_INVALID &&
70- iRet != DBRERR_1D_LICENSE_INVALID && iRet != DBRERR_PDF417_LICENSE_INVALID && iRet != DBRERR_DATAMATRIX_LICENSE_INVALID)
107+ if (iRet != DBR_OK && iRet != DBRERR_MAXICODE_LICENSE_INVALID && iRet != DBRERR_AZTEC_LICENSE_INVALID && iRet != DBRERR_LICENSE_EXPIRED && iRet != DBRERR_QR_LICENSE_INVALID && iRet != DBRERR_GS1_COMPOSITE_LICENSE_INVALID &&
108+ iRet != DBRERR_1D_LICENSE_INVALID && iRet != DBRERR_PDF417_LICENSE_INVALID && iRet != DBRERR_DATAMATRIX_LICENSE_INVALID && iRet != DBRERR_GS1_DATABAR_LICENSE_INVALID && iRet != DBRERR_PATCHCODE_LICENSE_INVALID)
71109 {
72- #if defined(WINDOWS)
73- sprintf_s (pszTemp, 4096 , " Failed to read barcode: %s\r\n " , DBR_GetErrorString (iRet));
74- printf (pszTemp);
75- free (pszTemp);
76- #else
77- printf (" Failed to read barcode: %s\r\n " , DBR_GetErrorString (iRet));
78- #endif
79-
110+ printf (" Failed to read barcode: %s\n " , CBarcodeReader::GetErrorString (iRet));
80111 return 0 ;
81112 }
82113
83- STextResultArray *paryResult = NULL ;
114+ TextResultArray *paryResult = NULL ;
84115 reader.GetAllTextResults (&paryResult);
85-
86- if (paryResult->nResultsCount == 0 )
116+
117+ if (paryResult->resultsCount == 0 )
87118 {
88119 printf (" No barcode found.\n " );
89120 CBarcodeReader::FreeTextResults (&paryResult);
90121 return 0 ;
91122 }
92123
93- printf (" Total barcode(s) found: %d. Total time spent: %d ms\n\n " , paryResult->nResultsCount , fCostTime );
94- for (int iIndex = 0 ; iIndex < paryResult->nResultsCount ; iIndex++)
124+ printf (" Total barcode(s) found: %d. Total time spent: %d ms\n\n " , paryResult->resultsCount , fCostTime );
125+ for (int iIndex = 0 ; iIndex < paryResult->resultsCount ; iIndex++)
95126 {
96127 printf (" Barcode %d:\n " , iIndex + 1 );
97- printf (" Type: %s\n " , paryResult->ppResults [iIndex]->pszBarcodeFormatString );
98- printf (" Text: %s\n " , paryResult->ppResults [iIndex]->pszBarcodeText );
128+ printf (" Type: %s\n " , paryResult->results [iIndex]->barcodeFormatString );
129+ printf (" Text: %s\n " , paryResult->results [iIndex]->barcodeText );
99130 }
100131
101- #if defined(WINDOWS)
102- free (pszTemp);
103- #endif
104132 CBarcodeReader::FreeTextResults (&paryResult);
105-
106133 return 0 ;
107134}
0 commit comments