How to Print Aztec Barcodes in Visual C++ (VC++)

Integrate high-speed Aztec barcode generation into your Visual C++ applications using the Barcodesoft BCSAztec TrueType font and COM components.

Core Components Required

To implement Aztec encoding in VC++, ensure the following files are present:

  • 1. bcsaztec.ttf: The specialized TrueType font for barcode rendering.
  • 2. cruflbcs.dll: The COM library providing the IAztec interface.
Note: After installation, the DLL is typically located in:
C:\Program Files (x86)\Common Files\Barcodesoft\Fontutil\

Method 1: Late Binding

Ideal for version-independent code. Use this when type information is unavailable at compile time.

CoInitialize(NULL); 
CLSID clsid;
if (FAILED(::CLSIDFromProgID(L"cruflbcs.Aztec.1", &clsid))) return 0;

IDispatch* pIDispatch = NULL;
::CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void**)&pIDispatch);

// Invoke Encode method
LPOLESTR szNameEncode = L"Encode";
DISPID dispid_encode;
pIDispatch->GetIDsOfNames(IID_NULL, &szNameEncode, 1, LOCALE_SYSTEM_DEFAULT, &dispid_encode);

VARIANTARG v[1];
v[0].vt = VT_BSTR; v[0].bstrVal = SysAllocString(L"Barcodesoft Sample");
DISPPARAMS dispParams = { v, NULL, 1, 0 };
VARIANT vResult;
pIDispatch->Invoke(dispid_encode, IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD, &dispParams, &vResult, NULL, NULL);

pIDispatch->Release();
CoUninitialize();

Method 2: Early Binding

Recommended for maximum performance. Requires access to the type library at compile time.

#include <atlbase.h>
#include <atlconv.h>
#import "cruflbcs.dll"
using namespace cruflBCS;

USES_CONVERSION;
CoInitialize(NULL);
_bstr_t bstrOutput;
char pszToEncode[] = "Barcodesoft Sample";

try {
    cruflBCS::IAztecPtr pBcsAztec(__uuidof(CBcsAztec));
    bstrOutput = pBcsAztec->Encode(T2OLE(pszToEncode));
} catch (const _com_error& e) {
    _tprintf(_T("Error: 0x%08x %s\n"), e.Error(), e.ErrorMessage());
}
CoUninitialize();

Using MFC to Generate Wrapper Classes

Steps for Modern Visual Studio:

  1. Select Add Class from the Project menu.
  2. Choose MFC Class from Typelib.
  3. Select Registry and locate crUFLBCS.
  4. Add the IAztec interface to your project.
  5. Initialize using OleInitialize(NULL).

// MFC Implementation

CString strOutput;
IAztec *pAztecObj = new IAztec();
if (pAztecObj->CreateDispatch("cruflbcs.Aztec.1")) {
    strOutput = pAztecObj->Encode("Barcodesoft Sample");
}