Using TBarCode Library

Important Functions

The main calls for generating a barcode are listed below in their normal order. Complete all barcode settings before calling BCCreate(). Only query generated values or draw and save the barcode after BCCreate() has returned ErrOk.

BCLicenseMe()
Applies the license and removes demo restrictions. Call it before drawing a barcode.
BCAlloc()
Allocates and initializes a barcode structure and returns the t_BarCode pointer used by subsequent calls.
BCSetBCType()
Selects the barcode symbology, such as Code 39, Code 128, UPC, EAN, or Data Matrix.
BCSetText()
Sets the data to encode.
BCSetModWidth() (optional)
Sets a specific module width. If it is not set, TBarCode Library computes a module width from the requested bounding rectangle and the current data.
Additional barcode properties (optional)
Set any additional properties required by the application, for example BCSet_PDF417_RowHeight(), BCSetCDMethod(), BCSetBearerBarWidth(), BCSetRatio(), BCSetTextDist(), and BCSetLogFont().
BCCheck() (optional)
Validates the input characters for the selected symbology. It must precede BCCalcCD() when both optional calls are used. BCCreate() performs this validation automatically.
BCCalcCD() (optional)
Calculates check digits for the selected check-digit method and adds them to the barcode data. Symbology-internal check digits, such as Code 128 modulo 103, are always produced by the symbology and are not calculated by this function. BCCreate() invokes this calculation automatically when required.
BCCreate()
Creates the internal barcode representation from the current data and properties. It returns ErrOk on success or an ERRCODE describing the failure. Do not change barcode properties or input data after a successful call.
Calculated barcode properties (optional)
After BCCreate() has returned ErrOk, you can retrieve calculated dimensions, module and row counts, and check digits. Use BCGetBarcodeSize() to obtain width and height together. Use BCGetBarcodeWidth() or BCGetBarcodeHeight() when only one dimension is required.
BCDraw()
Draws the barcode into a Windows device context within a bounding rectangle. This function is available only in TBarCode Library for Windows and requires a successful BCCreate() call.
Output functions
Save the barcode to a file or memory buffer. Select a function that matches the required format as described in Output Functions and Formats.
BCFree()
Releases the barcode structure. Call it last, including on error paths after a successful allocation.

If an API call returns an error other than ErrOk, do not call later barcode-processing functions with that structure except BCFree(). Handle the error first.

Output Functions and Formats

After BCCreate() has returned ErrOk, the same barcode can be drawn or written to one or more outputs:

Output File or device function Memory function Notes
Windows device context BCDraw() - Windows only
BMP, EMF, GIF, JPEG, PCX, PNG, TIFF, EPS, PCL, SVG, or AI BCSaveImage() BCSaveImageToBuffer() Windows only; select the format with e_IMType
PDF BCPDFToFile() BCPDFToMemory() PDF document output
EPS or PostScript BCPostscriptToFile() BCPostscriptToMemory() The file function creates Encapsulated PostScript (EPS)
PCL BCPCLToFile() BCPCLToMemory() Printer output
SVG BCSVGToFile() BCSVGToMemory() Vector output
Adobe Illustrator BCAIToFile() BCAIToMemory() AI version 7 output
Custom drawing BCDrawCB() - Uses registered drawing callbacks; see Custom Drawing Functions

Calling Order

Configure the barcode before supplying its data. Set the barcode type and all properties that affect how the input is interpreted, such as character encoding and escape-sequence processing, before calling BCSetText(). Use the following order:

  1. Apply the license when required and allocate the barcode structure with BCAlloc().
  2. Set the barcode type, escape-sequence translation, and all other barcode properties.
  3. Call BCSetText().
  4. Optionally call BCCheck() and BCCalcCD().
  5. Call BCCreate() and continue only if it returns ErrOk.
  6. If required, retrieve the calculated barcode dimensions and properties. Then draw or save the barcode with one or more output functions.
  7. Release the barcode structure with BCFree().

Calling Conventions

Use the declarations from tbarcode.h when calling the library. For native C/C++ calls, TECIT_STDCALL specifies __stdcall on Windows and is empty on Unix. TBARCODEDLL_API handles library import/export separately.

The API reference omits these technical macros from displayed signatures. Use the SDK header, including its calling convention, when declaring the API in another programming environment.

ANSI and Unicode

String APIs are available in ANSI and Unicode variants. ANSI functions have the suffix A; Unicode functions have the suffix W. Compatibility macros without a suffix select the Unicode function when _UNICODE is defined and the ANSI function otherwise.

// ANSI text
BCSetTextA(t_BarCode* pBarCode, LPCSTR szText, LONG nLen);

// Unicode text
BCSetTextW(t_BarCode* pBarCode, LPCWSTR szText, LONG nLen);

// Compatibility macro: A or W according to _UNICODE
BCSetText(...);

Define _UNICODE before including tbarcode.h for a Unicode build:

#define _UNICODE
#include "tbarcode.h"

Search documentation

Search in
More scopes
Additional scopes

All contents