ByteScout Barcode Reader SDK - C++ (Unmanaged) - Read barcode From Memory - ByteScout

ByteScout Barcode Reader SDK – C++ (Unmanaged) – Read barcode From Memory

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Reader SDK – C++ (Unmanaged) – Read barcode From Memory

How to read barcode from memory in C++ (Unmanaged) and ByteScout BarCode Reader SDK

The tutorial below will demonstrate how to read barcode from memory in C++ (Unmanaged)

Sample source code below will show you how to cope with a difficult task like read barcode from memory in C++ (Unmanaged). Want to read barcode from memory in your C++ (Unmanaged) app? ByteScout BarCode Reader SDK is designed for it. ByteScout BarCode Reader SDK is the SDK for barcode decoding. Can read all popular types from Code 128, GS1, UPC and Code 39 to QR Code, Datamatrix, PDF417. Images, pdf, TIF images and live web camera are supported as input. Designed to handle documents with noise and defects. Includes optional splitter and merger for pdf and tiff based on barcodes. Batch mode is optimized for high performance with multiple threads. Decoded values can be exported to XML, JSON, CSV or into custom data format.

You will save a lot of time on writing and testing code as you may just take the C++ (Unmanaged) code from ByteScout BarCode Reader SDK for read barcode from memory below and use it in your application. Just copy and paste the code into your C++ (Unmanaged) application’s code and follow the instruction. Use of ByteScout BarCode Reader SDK in C++ (Unmanaged) is also explained in the documentation included along with the product.

You can download free trial version of ByteScout BarCode Reader SDK from our website to see and try many others source code samples for C++ (Unmanaged).

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

ReadFromMemory.cpp
      
// ReadFromMemory.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "atlbase.h" #import "c:\\Program Files\\Bytescout BarCode Reader SDK\\net4.00\\Bytescout.BarCodeReader.tlb" raw_interfaces_only using namespace Bytescout_BarCodeReader; int _tmain(int argc, _TCHAR* argv[]) { // Initialize COM. HRESULT hr = CoInitialize(NULL); // Create the interface pointer. IReaderPtr pIReader(__uuidof(Reader)); // set the registration name and key BSTR regname = ::SysAllocString(L"DEMO"); pIReader->put_RegistrationName(regname); SysFreeString(regname); BSTR regkey = ::SysAllocString(L"DEMO"); pIReader->put_RegistrationKey(regkey); SysFreeString(regkey); // Set barcode type to find _BarcodeTypeSelectorPtr pBarcodeTypesToFind; pIReader->get_BarcodeTypesToFind(&pBarcodeTypesToFind); pBarcodeTypesToFind->put_GS1DataBarExpanded(VARIANT_TRUE); // Get full path of sample barcode image file WCHAR file[MAX_PATH]; ::GetFullPathName(L"GS1DataBarExpanded.png", MAX_PATH, file, NULL); // Load file content to byte array (for demonstration purpose) HANDLE hFile = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD fileSize = GetFileSize(hFile, NULL); byte* pBuffer = new byte[fileSize]; DWORD numberOfBytesRead; ReadFile(hFile, pBuffer, fileSize, &numberOfBytesRead, NULL); CloseHandle(hFile); // Read barcode from memory IStream* stream = SHCreateMemStream(pBuffer, fileSize); hr = pIReader->ReadFromStream(stream); stream->Release(); delete[] pBuffer; // Get found barcode count long count; pIReader->get_FoundCount(&count); // Get found barcode information for (int i = 0; i < count; i++) { SymbologyType type; hr = pIReader->GetFoundBarcodeType(i, &type); wprintf(L"Barcode type: %d\n", type); float confidence; hr = pIReader->GetFoundBarcodeConfidence(i, &confidence); wprintf(L"Barcode confidence: %f\n", confidence); BSTR bstrValue; hr = pIReader->GetFoundBarcodeValue(i, &bstrValue); wprintf(L"Barcode value: %s\n", bstrValue); ::SysFreeString(bstrValue); wprintf(L"\n"); } if (count == 0) { wprintf(L"no barcodes found"); } // Uninitialize COM. CoUninitialize(); wprintf(L"\nHit key to continue\n"); getchar(); return 0; }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout BarCode Reader SDK Home Page

Explore ByteScout BarCode Reader SDK Documentation

Explore Samples

Sign Up for ByteScout BarCode Reader SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.cpp
      
// stdafx.cpp : source file that includes just the standard includes // ReadFromMemory.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout BarCode Reader SDK Home Page

Explore ByteScout BarCode Reader SDK Documentation

Explore Samples

Sign Up for ByteScout BarCode Reader SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

stdafx.h
      
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> // TODO: reference additional headers your program requires here

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout BarCode Reader SDK Home Page

Explore ByteScout BarCode Reader SDK Documentation

Explore Samples

Sign Up for ByteScout BarCode Reader SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

targetver.h
      
#pragma once // Including SDKDDKVer.h defines the highest available Windows platform. // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. #include <SDKDDKVer.h>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout BarCode Reader SDK Home Page

Explore ByteScout BarCode Reader SDK Documentation

Explore Samples

Sign Up for ByteScout BarCode Reader SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout BarCode Reader SDK Home Page

Explore ByteScout BarCode Reader SDK Documentation

Explore Samples

Sign Up for ByteScout BarCode Reader SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next