TBarCode Library 11  TBarCode Library 11

This example shows the error handling concept of TBarCode.

This example shows the error handling concept of TBarCode.

If BCCreate() returns any value other than zero (ErrOK) you might use the following function to get detailled information about the occured error.
For retrieving error texts see also BCGetErrorTextExt().

CString GetFullBCErrorText
(
t_BarCode* pBarCode, // IN: pointer to barcode struct
ERRCODE eCode // IN: last occurred error code
)
{
CString sErrorText;
TCHAR szBuffer[70] = {0};
LPTSTR szErrorMsg = szBuffer;
CString sWrongChar;
LPTSTR szCCError = _T("");
BCGetErrorText(eCode, szBuffer, (sizeof(szBuffer)/sizeof(szBuffer[0]))-1); // retrieve error information
if (BCGet2DCompositeComponent(pBarCode) != eCC_None) // was a composite symbol requested?
{
BOOL bErrinCC = BCGet_CompSym_ErrorInCC(pBarCode);
// error in the composite or linear component?
szCCError = bErrinCC ? _T("in 2D Composite Component") : _T("in linear component") ;
// maybe a composite component was requested, which is not allowed for the basic linear barcode type
if (bErrinCC && eCode == W32toTEC(ERROR_NOT_SUPPORTED))
{
szCCError = _T("in Composite Symbology");
szErrorMsg = _T("Composite Component not supported for the selected barcode type");
}
}
// or the user supplied invalid data (not all characters can be encoded with the selected barcode type)
if (eCode == W32toTEC(ERROR_INVALID_DATA))
{
INT nPos = BCGetInvalidDataPos(pBarCode);
CString sData = GetDocument()->GetData();
CString sHex;
// show the wrong character
if (nPos >= 0 && nPos < sData.GetLength())
{
if (!isgraph(sData.GetAt(nPos)))
sHex.Format(" (ASCII Code 0x%X)", sData.GetAt(nPos) & 0xff);
sWrongChar.Format("'%c' at position %d%s", sData.GetAt(nPos) & 0xff, nPos+1, sHex);
}
}
else if (eCode == NTE_BAD_LEN)
{
// barcode needs a specific number of input characters
// retrieve number of needed characters (data + check-digit)
INT nLen = BCGetMaxLenOfData(BCGetBCType(pBarCode));
// check if wrong character position is available (-1 = not available)
if (nLen > 0)
{
INT nLenCD = BCGetCheckDigits(pBarCode, NULL, 0);
nLenCD = (nLenCD < 0) ? 0 : nLenCD;
// the check-digit need not to be part of input data
sWrongChar.Format(" (needs %d chars)", nLen - nLenCD);
}
}
// this would be our final error message to the user
sErrorText.Format(_T("Error %s: %s%s!"), szCCError, (LPCSTR) szErrorMsg, sWrongChar); //FormatMessage
return sErrorText;
}
BOOL TECIT_STDCALL BCGet_CompSym_ErrorInCC(t_BarCode *pBarCode)
Determines the source of the error when creating composite symbologies.
Definition: compsymapi.cpp:110
e_CCType TECIT_STDCALL BCGet2DCompositeComponent(t_BarCode *pBarCode)
Gets adjusted 2D Composite Component.
Definition: compsymapi.cpp:25
LONG TECIT_STDCALL BCGetMaxLenOfData(e_BarCType eType)
Returns the number of characters for a specified barcode.
Definition: dataapi.cpp:39
INT TECIT_STDCALL BCGetInvalidDataPos(t_BarCode *pBarCode)
Gets position of invalid character in input data.
Definition: errorapi.cpp:808
e_BarCType TECIT_STDCALL BCGetBCType(t_BarCode *pBarCode)
Gets the barcode type (symbology) currently adjusted.
Definition: bctypeapi.cpp:78
#define BCGetCheckDigits
Definition: tbarcode.h:277
#define ERRCODE
Data type for error codes.
Definition: tbarcode.h:170
#define BCGetErrorText
Definition: tbarcode.h:296
struct tag_BarCode t_BarCode
Forward declaration of the internal used barcode structure.
Definition: tbarcode.h:154

© 2023 All rights reserved by TEC-IT Datenverarbeitung GmbH
Generated on Wed Apr 10 2024 13:55:58 for TBarCode Library 11 with doxygen 1.9.1