010-68421378
sales@cogitosoft.com
Categories
AddFlow  AmCharts JavaScript Stock Chart AmCharts 4: Charts Aspose.Total for Java Altova SchemaAgent Altova DatabaseSpy Altova MobileTogether Altova UModel  Altova MapForce Altova MapForce Server Altova Authentic Aspose.Total for .NET Altova RaptorXML Server ComponentOne Ultimate Chart FX for SharePoint Chart FX CodeCharge Studio ComponentOne Enterprise combit Report Server Combit List & Label 22 Controls for Visual C++ MFC Chart Pro for Visual C ++ MFC DbVisualizer version 12.1 DemoCharge DXperience Subscription .NET DevExpress Universal Subscription Essential Studio for ASP.NET MVC FusionCharts Suite XT FusionCharts for Flex  FusionExport V2.0 GrapeCity TX Text Control .NET for WPF GrapeCity Spread Studio Highcharts Gantt Highcharts 10.0 版 HelpNDoc Infragistics Ultimate  ImageKit9 ActiveX ImageKit.NET JetBrains--Fleet JetBrains-DataSpell JetBrains--DataGrip jQuery EasyUI jChart FX Plus OPC DA .NET Server Toolkit  OSS ASN.1/C Oxygen XML Author  OSS 4G NAS/C, C++ Encoder Decoder Library OSS ASN.1 Tools for C with 4G S1/X2 OSS ASN.1/C# OSS ASN.1/JAVA OSS ASN.1/C++ OPC HDA .NET Server Toolkit OPC DA .Net Client Development Component PowerBuilder redgate NET Developer Bundle Report Control for Visual C++ MFC  Sencha Test SPC Control Chart Tools for .Net Stimulsoft Reports.PHP Stimulsoft Reports.JS Stimulsoft Reports.Java Stimulsoft Reports. Ultimate Stimulsoft Reports.Wpf Stimulsoft Reports.Silverlight SlickEdit Source Insight Software Verify .Net Coverage Validator Toolkit Pro for VisualC++MFC TeeChart .NET Telerik DevCraft Complete Altova XMLSpy Zend Server

Dynamsoft Barcode Reader C C++ API

Using Dynamsoft Barcode Reader C++ API in Windows

Dynamsoft's C++ Barcode Reader library for Windows allows you to almost instantly embed 1D and 2D barcode reading functionality in your Windows Desktop applications. I am going to demonstrate how to use the C++ barcode reading API for Windows to build a Win32 Console Application for barcode recognition.

START A NEW FILE

New a console application

First, let's open Visual Studio.

Create an empty Win32 Console Application project through Visual C++>Win32.

Let's name it BarcodeReaderC++API

Add references

Following this guide, first, reference the .H and .LIB files. To make it easier, let's copy the Include folder and the Lib folder from the installation directory to the project.

Change the relative path here.

#include

#include "/If_DBRP.h"

#ifdef _WIN64

#pragma comment ( lib, "/x64/DBRx64.lib" )

#else

#pragma comment ( lib, "/x86/DBRx86.lib" )

#endif

Copy the main function

Next, insert the following code to the main function.

 

//Define variables

const char * pszImageFile = "";

int iIndex = 0;

int iRet = -1;

       

//Initialize license prior to any decoding

CBarcodeReader reader;

reader.InitLicense("");

 

//Initialize ReaderOptions

ReaderOptions ro = {0};          

ro.llBarcodeFormat = OneD;   //Expected barcode types to read.

ro.iMaxBarcodesNumPerPage = 100;     //Expected barcode numbers to read.

reader.SetReaderOptions(ro);

 

//Start decoding

iRet = reader.DecodeFile(pszImageFile);

 

//If not DBR_OK

if (iRet != DBR_OK)

{

  printf("Failed to read barcode: %d\r\n%s\r\n",iRet, GetErrorString(iRet));

  return iRet;

}

 

//If DBR_OK

pBarcodeResultArray paryResult = NULL;

reader.GetBarcodes(&paryResult);

printf("%d total barcodes found. \r\n", paryResult->iBarcodeCount);

for (iIndex = 0; iIndex < paryResult->iBarcodeCount; iIndex++)

{

  printf("Result %d\r\n", iIndex + 1);

  printf("PageNum: %d\r\n", paryResult->ppBarcodes[iIndex]->iPageNum);

  printf("BarcodeFormat: %lld\r\n", paryResult->ppBarcodes[iIndex]->llFormat);

  printf("Text read: %s\r\n", paryResult->ppBarcodes[iIndex]->pBarcodeData);

}

 

//Finally release BarcodeResultArray

CBarcodeReader::FreeBarcodeResults(&paryResult);

Update source image

Change the image path. I am going to use a sample image from the installation folder. Copy the file path, add the escape character, and then the file name. Change the path to "C:\\Program Files (x86)\\Dynamsoft\\Barcode Reader 4.1\\Images\\AllSupportedBarcodeTypes.tif".

 

const char * pszImageFile = "C:\\Program Files (x86)\\Dynamsoft\\Barcode

 Reader 4.1\\Images\\AllSupportedBarcodeTypes.tif";

             

Build the project. Build Succeeded.

Copy barcode DLLs

Go to the installation directory, under the Components\C_C++\Redist folder, copy the two DLLs - DynamsoftBarcodeReaderx86.dll and DynamsoftBarcodeReaderx64.dll. Paste them to the same folder as BarcodeReaderC++API.exe, which is under the Debug folder of the solution by default.

Press Ctrl+F5 to run the project. OK. We've got all the barcodes recognized.

Review the code

Now, let's go over the code quickly. First, we define variables including the image path. And then we configure the license info. With this snippet, we initialize the barcode reading options, such as barcode types, and how many barcodes to read per page. Call the DecodeFile method to decode the barcodes. If there are multiple barcodes found, we use a loop to print out the results one by one.

 

//Start decoding

iRet = reader.DecodeFile(pszImageFile);

 

//If not DBR_OK

if (iRet != DBR_OK)

{

  printf("Failed to read barcode: %d\r\n%s\r\n",iRet, GetErrorString(iRet));

  return iRet;

}

 

//If DBR_OK

pBarcodeResultArray paryResult = NULL;

reader.GetBarcodes(&paryResult);

printf("%d total barcodes found. \r\n", paryResult->iBarcodeCount);

for (iIndex = 0; iIndex < paryResult->iBarcodeCount; iIndex++)

{

  printf("Result %d\r\n", iIndex + 1);

  printf("PageNum: %d\r\n", paryResult->ppBarcodes[iIndex]->iPageNum);

  printf("BarcodeFormat: %lld\r\n", paryResult->ppBarcodes[iIndex]->llFormat);

  printf("Text read: %s\r\n", paryResult->ppBarcodes[iIndex]->pBarcodeData);

}

Remember to release BarcodeResultArray

Last but not the least, we need to release BarcodeResultArray. Please note this step is very important.

 

//Finally release BarcodeResultArray

CBarcodeReader::FreeBarcodeResults(&paryResult);

Other barcode reading functionality

Finally, if you want to decode barcodes from a specific area of an image, there is a DecodeFileRect Method. Dynamsoft's Barcode Reader SDK also supports reading barcodes from device-independent bitmap (a.k.a., DIB), buffer and base64 string.

Quick Navigation;

© Copyright 2000-2023  COGITO SOFTWARE CO.,LTD. All rights reserved