Windows C++ SDK - Installation
About the barKoder SDK for C++ on Windows #
The barKoder SDK for Windows includes a native C++ library built with Visual Studio 2022. This guide shows how to add it to a C++ console application. For Linux, see C++ SDK - Installation.
Requirements #
- Visual Studio 2022 (earlier versions are not guaranteed to work).
- x64 or ARM64 for OCR/MRZ features. Barcode-only builds also include x86 (Win32) libraries.
- A valid trial or production license key.
Core Components #
-
Barkoder.lib/Barkoder.dll: the main barcode decoding library. -
libiconv.lib/libiconv.dll: text encoding and conversion support. -
The SDK header files, including
Barkoder.hpp,Config.hppand the C wrapperBarkoderWrapper.h.
The libraries are in the Windows SDK download from the barKoder Repository, per platform and configuration (Debug, Release, Debug OCR, Release OCR), together with the sample_cpp project.
Quick Start #
1. Add the library files #
Add the .lib files for your target platform and configuration to your project: in Project Settings → Linker → General, add the SDK library directory to Additional Library Directories.
2. Deploy the DLL files #
Copy the matching .dll files to your project's output directory:
Platform/Configuration/
├── Barkoder.dll
├── libiconv.dll
└── YourApp.exe
3. Include the header files #
Copy the SDK header files to your project and include them in your source files:
#include "Barkoder.hpp"
#include "Config.hpp"
// ... other SDK headers
For projects that use the static CRT (/MT or /MTd), include the C wrapper header as well:
#include "BarkoderWrapper.h"
4. Initialize with a license key #
ConfigResponse response = Config::InitializeWithLicenseKey("YOUR_LICENSE_KEY_HERE");
Config* config = response.GetConfig();
5. Configure the decoder #
// Enable specific barcode types
config->SetEnabledDecoders({
DecoderType::QR,
DecoderType::Code128,
DecoderType::Code39
// ... add other types as needed
});
// Adjust decoding speed
config->SetDecodingSpeed(DecodingSpeed::Fast);
6. Build and run #
Build your application and run it with an image file as the only argument:
YourApp.exe path\to\barcode-image.bmp
Runtime Library Compatibility (/MD vs /MT) #
-
Use the native C++ API (
Barkoder.hpp,Config.hpp) when your app uses the dynamic CRT (/MD,/MDd). -
Use the C wrapper API (
BarkoderWrapper.h) when your app uses the static CRT (/MT,/MTd), or when the CRT settings of your app and the DLL may differ.
Complex C++ types such as std::string, std::vector and std::unordered_map are not ABI-safe across DLL boundaries when CRT settings do not match. The C wrapper exposes only C-compatible types and handles.
/MD flow (native C++) #
ConfigResponse response = Config::InitializeWithLicenseKey("YOUR_KEY");
Config* config = response.GetConfig();
std::vector<BaseResult> results = Barkoder::DecodeImageMemory(config, pixels, width, height);
/MT flow (C wrapper) #
ConfigHandle configHandle = nullptr;
char errorMessage[512] = {0};
if (Config_InitializeWithLicenseKey("YOUR_KEY", &configHandle, errorMessage, sizeof(errorMessage)) == 0 || !configHandle) {
// Continue in demo mode if needed
Config_DefaultConfig(&configHandle);
}
// Configure and decode via the C API
Config_SetEnabledDecoders(configHandle, decoders, sizeof(decoders) / sizeof(decoders[0]));
ResultHandle* results = nullptr;
int resultCount = 0;
Barkoder_DecodeImageMemory(configHandle, pixels, width, height, BK_COLORFORMAT_GRAYSCALE, &results, &resultCount, errorMessage, sizeof(errorMessage));
// Process results...
// Cleanup
Barkoder_DestroyResults(results, resultCount);
Config_Destroy(configHandle);
The included sample_cpp project selects the API path at compile time (/MT uses the C wrapper, /MD the native C++ API). Keep runtime libraries consistent per configuration: Debug with the Debug CRT, Release with the Release CRT.
Image Format Support #
CImg.h, which supports 24-bit BMP only. For JPEG, PNG and other formats, use an image loading library such as OpenCV, stb_image, FreeImage or the Windows Imaging Component (WIC), and pass the decoder a grayscale buffer.OCR / MRZ Features #
1. Deploy the OCR resources #
Copy all files from the OCR_Resources folder to your executable directory, next to Barkoder.dll and onnxruntime.dll. Alternatively, set the BKOCR_RESOURCES_PATH environment variable to the folder that holds the OCR resources:
rem Windows Command Prompt
set BKOCR_RESOURCES_PATH=C:\Path\To\OCR_Resources
# Windows PowerShell
$env:BKOCR_RESOURCES_PATH="C:\Path\To\OCR_Resources"
2. Use an OCR build configuration #
Select Debug OCR for development or Release OCR for production. OCR/MRZ is supported on x64 and ARM64 only.
3. Enable MRZ (ID document) reading #
config->SetEnabledDecoders({DecoderType::IDDocument});
4. Enable general OCR text reading #
config->SetEnabledDecoders({DecoderType::OCRText});
config->SetCustomOption("enable_ocr_functionality", 1);
Troubleshooting #
-
Build errors: check that Visual Studio 2022 is installed, the library paths are set, and the platform (x64/ARM64) matches across all components. If you see
System::Object not found, disable/clrfor native C++ builds. If_CrtDbgReportis unresolved in Debug, check the Runtime Library setting and avoid mixing CRT/debug libraries. - Runtime errors: check that the DLLs are in the executable directory, that DLL and LIB versions match (Debug with Debug, Release with Release), and that the license key is valid.
- OCR not working: use the Debug OCR or Release OCR configuration, deploy the OCR resource files, use a license that includes OCR/MRZ, and build for x64 or ARM64 (Win32 is not supported).