Your location:Home>翻译软件 条码 证书>条码软件

Dynamsoft Barcode Reader C/C ++ API for Mac

Dynamsoft Barcode Reader C/C++ API for Mac

Using Dynamsoft Barcode Reader C++ API for Mac

Dynamsoft's Barcode Reader SDK provides C++ and C APIs for Mac. You can use the barcode APIs to easily create a barcode reading software for Mac.In this article, I am going to demonstrate how to use the C++ barcode reading API for Mac to build a Command Line Application for 1D and 2D barcode recognition on Mac OS X.

START A NEW FILE

New a Command Line Tool

First, let's open Xcode.

Choose Command Line Tool as the project template, and under Type select C++ stdc++. Let's name the project BarcodeReaderDemo.

Add references

In the main.cpp, please include the .H files.

In our case, if you have Barcode Reader installed under Applications, the path will be"/Applications/Dynamsoft/Barcode Reader 4.1/Include/If_DBRP.h."

#include

#include "/Applications/Dynamsoft/Barcode Reader 4.1/Include/If_DBRP.h"

Copy the main function

Next, insert the following code to the main function.

int  main  ( int  argc,   const  char *  argv[ ] )

{

   //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);

       

   return 0;

}

Select linked library

Select Targets -> BarcodeReaderDemo, click Info button, in the popped dialog, addlibDynamsoftBarcodeReader.dylib dependency.

Update license and source image

Please update the  and  with valid values respectively in the code.

For image path, you can use AllSupportedBarcodeTypes.tif in Images folder.
For license key, please find it in BarcodeReaderTrialLic.txt.

const char * pszImageFile = "/Applications/Dynamsoft/Barcode Reader 4.1/

Images/AllSupportedBarcodeTypes.tif";

               

Now you can build the project and have a run.

Barcode result

To verify if it is working, please open Terminal.app, and execute the application.

北京哲想软件有限公司