Barcode Reader SDK for Windows. Usage

This page will demonstrate how to install the SDK and use the SD-TOOLKIT Barcode Reader SDK API from different programming languages.

Installing the SDK

  1. Download and run SDTBarcodeSetup.exe
  2. Follow the Setup Wizard instructions. When asked enter your Developer licnese key or leave the field blank to activate trial license on your computer. The one-time internet connection is required during installation.
  3. Once setup has finished the folder C:\Program Files\SD-Toolkit\SDTBarcodeSDK will contain runtime components, documentation and sample applications with sourcecode for your reference.

Reading Barcodes from C# Windows Application

The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Samples\SDTBarcodeSampleCSharp.

show screenshots

  1. Install the SDK.
  2. In MS Visual Studio Create new C# Windows Application project
  3. In form design view add button. Set Name property to openFile and Text property to Open File and Read Barcode...
  4. In form design view add PictureBox. Set Name property to pictureBoxImage. We will use this control to show loaded image.
  5. In form design view add ListBox. Set Name property to listBoxResults. We will use it for showing recognition results.
  6. In the solution explorer click right mouse button on Project References and choose Add Reference... Point reference to the SDTBarcode.Net.dll assembly.
  7. In form design view add openFileDialog.
  8. In form design view double click on the openFile button. It will add OnButtonClick event handler for button openFile. Modify the openFile_Click handler to be the following:
    private void openFile_Click(object sender, EventArgs e)
        openFileDialog1.Filter = "All files (*.*)|*.*";
        if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            Cursor currentCursor = this.Cursor;
            this.Cursor = Cursors.WaitCursor;
            Bitmap imageToShow = (Bitmap)Bitmap.FromFile(openFileDialog1.FileName);
            //Setup Barcode Engine properties
            using (SDTBarcode.SDTBarcodeEngine barcodeEngine = new SDTBarcodeEngine("TRIAL"))
                barcodeEngine.SetActiveScanRectangle(0, 0, imageToShow.Width, imageToShow.Height);
                Int32 readResult = -1;
                readResult = barcodeEngine.ReadImageFile(openFileDialog1.FileName, 0);
                Graphics graph = Graphics.FromImage(imageToShow);
                if (readResult == 0)
                    long resultsCount = barcodeEngine.GetResultsCount();
                    for (Int32 i = 0; i < resultsCount; i++)
                        string resultValue = barcodeEngine.GetResultValue(i);
                        Int32 resultType = barcodeEngine.GetResultType(i);
                        string resultTypeName = barcodeEngine.GetResultTypeName(i);
                        if (resultValue != null)
                            if (resultTypeName != null)
                                resultValue += " (" + resultTypeName + ")";
                            graph.DrawRectangle(new Pen(Color.Red, 3),
                                                barcodeEngine.GetResultPositionRight(i) - barcodeEngine.GetResultPositionLeft(i),
                                                barcodeEngine.GetResultPositionBottom(i) - barcodeEngine.GetResultPositionTop(i));
            this.Cursor = currentCursor;
            pictureBoxImage.Image = imageToShow;
  9. Modify Doc properties of the Form controls.
  10. Build and run the application

Reading Barcodes from C++ Windows Application

The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Samples\SDTBarcodeSampleCpp.

  1. Install the SDK.
  2. In MS Visual Studio Create new C++ Windows Console Application project
  3. Modify newelly created project properties to refer to the SDTBarcode header file and library.

    C/C++ -> General-> Additional Include Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDK\Include
    Linker -> General ->Additional Library Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDK\lib\x86
    Linker -> Input ->Additional Dependencies: SDTBarcode.lib

  4. Modify stdafx.h to include <windows.h>.
  5. Initialize BarcodeEngine passing your purchased developer license as a parameter.
    void* pReader = SDTCreateBarcodeReaderW(L"License");
  6. Read the image file
    SDTReadImageFileW(pReader, L"C:\\Program Files (x86)\\SD-Toolkit\\SDTBarcodeSDK\\Images\\Ean13.jpg", 0);
  7. Show results in console
    if( SDTGetResultsCount(pReader) > 0 )
    	for( int i = 0; i < SDTGetResultsCount(pReader); i++ )
    		LPCWSTR value = SDTGetResultValueW(pReader, i);
    		LPCWSTR typeName = SDTGetResultTypeNameW(pReader, i);
    		__int32 type = SDTGetResultType(pReader, i);
    		__int32 direction = SDTGetResultReadDirection(pReader, i);
    		int left = 0, top = 0, right = 0, bottom = 0;
    		left = SDTGetResultPositionLeft(pReader, i);
    		top = SDTGetResultPositionTop(pReader, i);
    		right = SDTGetResultPositionRight(pReader, i);
    		bottom = SDTGetResultPositionBottom(pReader, i);
    		wprintf(L"Found Barcode: %s (%s) at pos:{%d,%d,%d,%d}\n", value, typeName, left, top, right, bottom);
  8. Destroy Barcode Endine
    pReader = NULL;