Skip to content

Commit 7ec63a4

Browse files
committed
Updated for DBR v7.2
1 parent 2a9589f commit 7ec63a4

File tree

4 files changed

+3602
-1351
lines changed

4 files changed

+3602
-1351
lines changed

BarcodeReader.cxx

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,57 @@
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+
960
void 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
}

CMakeLists.txt

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ project (BarcodeReader)
33
MESSAGE( STATUS "PROJECT_NAME: " ${PROJECT_NAME} )
44

55
# The version number.
6-
set(BarcodeReader_VERSION_MAJOR 6)
7-
set(BarcodeReader_VERSION_MINOR 3)
6+
set(BarcodeReader_VERSION_MAJOR 7)
7+
set(BarcodeReader_VERSION_MINOR 2)
88

99
# Check platforms
1010
if (CMAKE_HOST_WIN32)
@@ -32,13 +32,13 @@ configure_file (
3232

3333
# Add search path for include and lib files
3434
if(WINDOWS)
35-
link_directories("${PROJECT_SOURCE_DIR}/platforms/win")
35+
link_directories("${PROJECT_SOURCE_DIR}/platforms/win/lib/")
3636
elseif(LINUX)
37-
link_directories("${PROJECT_SOURCE_DIR}/platforms/linux")
37+
link_directories("${PROJECT_SOURCE_DIR}/platforms/linux/")
3838
elseif(MACOS)
39-
link_directories("${PROJECT_SOURCE_DIR}/platforms/macos")
39+
link_directories("${PROJECT_SOURCE_DIR}/platforms/macos/")
4040
endif()
41-
include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include")
41+
include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include/")
4242

4343
# Add the executable
4444
add_executable(BarcodeReader BarcodeReader.cxx)
@@ -53,42 +53,26 @@ else()
5353
endif()
5454

5555
if(WINDOWS)
56-
# Copy DLL files to output directory
57-
if(CMAKE_CL_64)
58-
add_custom_command(TARGET BarcodeReader POST_BUILD
59-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
60-
"${PROJECT_SOURCE_DIR}/platforms/win/DynamsoftBarcodeReaderx64.dll"
61-
$<TARGET_FILE_DIR:BarcodeReader>)
62-
else()
63-
add_custom_command(TARGET BarcodeReader POST_BUILD
64-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
65-
"${PROJECT_SOURCE_DIR}/platforms/win/DynamsoftBarcodeReaderx86.dll"
66-
$<TARGET_FILE_DIR:BarcodeReader>)
67-
endif()
68-
6956
add_custom_command(TARGET BarcodeReader POST_BUILD
7057
COMMAND ${CMAKE_COMMAND} -E copy_directory
71-
"${PROJECT_SOURCE_DIR}/templates"
72-
$<TARGET_FILE_DIR:BarcodeReader>/"templates" )
58+
"${PROJECT_SOURCE_DIR}/platforms/win/bin/"
59+
$<TARGET_FILE_DIR:BarcodeReader>)
60+
7361
endif()
7462

7563
# Set installation directory
7664
if(WINDOWS)
7765
set(CMAKE_INSTALL_PREFIX "e:/${PROJECT_NAME}")
78-
if(CMAKE_CL_64)
79-
install (FILES "${PROJECT_SOURCE_DIR}/platforms/win/DynamsoftBarcodeReaderx64.dll" DESTINATION bin)
80-
else()
81-
install (FILES "${PROJECT_SOURCE_DIR}/platforms/win/DynamsoftBarcodeReaderx86.dll" DESTINATION bin)
82-
endif()
66+
install (DIRECTORY "${PROJECT_SOURCE_DIR}/platforms/win/bin/" DESTINATION bin)
8367
elseif(LINUX)
84-
install (FILES "${PROJECT_SOURCE_DIR}/platforms/linux/libDynamsoftBarcodeReader.so" DESTINATION lib)
68+
install (DIRECTORY "${PROJECT_SOURCE_DIR}/platforms/linux/" DESTINATION lib)
8569
elseif(MACOS)
86-
install (FILES "${PROJECT_SOURCE_DIR}/platforms/macos/libDynamsoftBarcodeReader.dylib" DESTINATION lib)
70+
install (DIRECTORY "${PROJECT_SOURCE_DIR}/platforms/macos/" DESTINATION lib)
8771
endif()
8872

8973
install (TARGETS BarcodeReader DESTINATION bin)
9074
install (FILES "${PROJECT_BINARY_DIR}/BarcodeReaderConfig.h" DESTINATION include)
91-
install (DIRECTORY "${PROJECT_SOURCE_DIR}/include" DESTINATION include)
75+
install (DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION include)
9276

9377
# Use CTest
9478
include(CTest)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Building C/C++ Barcode Reader with CMake
22

3-
Version 6.3
3+
Version 7.2
44

55
## License
66
Get the [trial license](https://www.dynamsoft.com/CustomerPortal/Portal/Triallicense.aspx).
@@ -15,7 +15,7 @@ https://www.dynamsoft.com/Company/Contact.aspx
1515
* [Dynamsoft Barcode Reader](https://www.dynamsoft.com/Downloads/Dynamic-Barcode-Reader-Download.aspx).
1616

1717
### Steps
18-
1. Copy **DBRx86.lib/DBRx64.lib** and **DynamsoftBarcodeReaderx86.dll/DynamsoftBarcodeReaderx64.dll** to **platforms\win** folder.
18+
1. Copy `DBRx86.lib/DBRx64.lib` to `platforms\win\lib` and copy `DynamsoftBarcodeReaderx86.dll/DynamsoftBarcodeReaderx64.dll` to `platforms\win\bin` folder.
1919
2. Create a **build** folder:
2020
```
2121
mkdir build

0 commit comments

Comments
 (0)