Resource Base
Table of contents
Notice: This documentation is archived. For the latest product features and documentation, please visit Dynamsoft Capture Vision Documentation.

Getting Started with C++ Edition

In this guide, you will learn step by step on how to build a code parsing application with Dynamsoft Code Parser SDK using C++ language.

Requirements

  • Operating System:
    • Windows 7, 8, 10, 11, 2003, 2008, 2008 R2, 2012, 2016, 2019, 2022
    • Linux x64: Ubuntu 14.04.4+ LTS, Debian 8+, etc
  • Developing Tool
    • Visual Studio 2012 or above
    • G++ 5.4+

Note: Dynamsoft Code Parser provides both online and offline license options. The online license option might not work in an environment that doesn’t have network connection. In such case, you can get an offline trial license key via Customer Portal or by contacting us.

Installation

If you haven’t downloaded the SDK yet, download the C/C++ Package now from Dynamsoft website and unpack the package into the directory of your choice.

For this tutorial, we unpack it to [INSTALLATION FOLDER], change it to your unpacking path for the following content.

Build Your First Application

Let’s start by creating a console application which demonstrates how to use the minimum code to get the human-readable information from the code string.

You can download the entire source code here.

Create a New Project

For Windows

  1. Open Visual Studio. Go to File > New > Project, create a new Empty Project and set Project name as DCPSample.

  2. Add a new source file named DCPSample.cpp into the project.

For Linux/ARM/Mac

Create a new source file named DCPSample.cpp and place it into the folder [INSTALLATION FOLDER]/Samples.

Include the Library

Add headers and libs in DCPSample.cpp.

#include<iostream>
#include "[INSTALLATION FOLDER]/Include/DynamsoftCodeParser.h"
#include "[INSTALLATION FOLDER]/Include/DynamsoftCore.h"
#include "[INSTALLATION FOLDER]/Include/DynamsoftLicense.h"
using namespace std;
using namespace dynamsoft::dcp;
using namespace dynamsoft::license;
#if defined(_WIN64) || defined(_WIN32)
    #ifdef _WIN64
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x64/DynamsoftCodeParserx64.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x64/DynamsoftCorex64.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x64/DynamsoftLicensex64.lib")
    #else
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x86/DynamsoftCodeParserx86.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x86/DynamsoftCorex86.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Lib/Windows/x86/DynamsoftLicensex86.lib")
    #endif
#endif

Initialize a Code Parser Instance

Initialize the license key.

int errorCode = 0;
char errorBuf[512];
errorCode = CLicenseManager::InitLicense("YOUR-LICENSE-KEY",errorBuf, 512);
if (errorCode != EC_OK)
{
    // Add your code for license error processing;
    cout << errorBuf << endl;
}

Please replace YOUR-LICENSE-KEY with a valid DCP licensekey. There are two ways to obtain one:

  • Search InitLicense and find the license from [INSTALLATION FOLDER]/Samples/HelloWorld/HelloWorld.cpp.
  • Request a trial license from Customer Portal.

Create an instance of Dynamsoft Code Parser.

CCodeParser* dcp = new CCodeParser();

Parse and Output Results

Parse a code string.

int errorCode = -1;
//get codeString and codeStringLength somewhere else
CParsedResultItem* dcpResult = dcp->Parse(codeString, codeStringLength, "", &errorCode);

Get and output results.

if (dcpResult != NULL)
{
    cout << "CodeType: " << dcpResult->GetCodeType() << endl;
    cout << "Value of A-SPECIFIC-FIELD-NAME: " << dcpResult->GetFieldValue("A-SPECIFIC-FIELD-NAME") << endl;
}

Please replace A-SPECIFIC-FIELD-NAME to a specific field name based on the code string you are parsing. Check out Supported Code Types and Fields for details.

Release Allocated Memory

Release the allocated memory for the barcode results.

if (dcpResult != NULL)           
    delete dcpResult;

Release the allocated memory for the instance.

if (dcp != NULL)           
    delete dcp;

Note:
Please change all [INSTALLATION FOLDER] in above code snippet to your unpacking path.

Build and Run the Project

For Windows

  1. In Visual Studio, set the solution to build as Release|x64.

  2. Build the project to generate program DCPSample.exe.

  3. Copy ALL *.dll files under [INSTALLATION FOLDER]\Lib\Windows\x64 to the same folder as the DCPSample.exe.

  4. Run the program DCPSample.exe.

The SDK supports both x86 and x64, please set the platform based on your needs.

For Linux

Open a terminal and change to the target directory where DCPSample.cpp located in. Build the sample:

g++ -o DCPSample DCPSample.cpp -lDynamsoftCodeParser -lDynamsoftCore -lDynamsoftLicense -L ../Lib/Linux -Wl,-rpath=../Lib/Linux -std=c++11

Run the program DCPSample.

./DCPSample

You can download the entire source code here.

version 2.0.10

  • version 2.4.10
  • Version 2.x
    • Version 2.2.10
    • Version 2.2.0
    • Version 2.0.20
    • Version 2.0.10
    • Version 2.0.0
Change +