Error Handling

Error handling functions. More...
VOID BCGetErrorTextA (ERRCODE eCode, LPSTR szText, size_t nSize)
 Returns error text to given error-code.
VOID BCGetErrorTextW (ERRCODE eCode, LPWSTR szText, size_t nSize)
 Returns error text to given error-code.
VOID BCGetErrorTextExtA (t_BarCode *pBarCode, ERRCODE eCode, LPSTR szText, size_t nSize)
 Returns extended error text to given error-code.
VOID BCGetErrorTextExtW (t_BarCode *pBarCode, ERRCODE eCode, LPWSTR szText, size_t nSize)
 Returns extended error text to given error-code.

Functions

INT BCGetInvalidDataPos (t_BarCode *pBarCode)
 Gets position of invalid character in input data.

Detailed Description

Error handling functions.

Error Codes
Here is a list of error-codes which are used by TBarCode and may be returned to the user. Operating system specific error-codes are not listed. Error codes are specified in hexadecimal notation (0x). If any of the BCxxxx functions returns an error code not equal to zero (ErrOk) than DO NOT call subsequent BCxxxx functions except of BCFree(). An error code indicates an error condition and subsequent calls (except to BCFree) may fail and produce unexpected results.
Error Handling
This chapter demonstrates proper error-handling. It shows how to create an appropriate error message if you receive an error code from BCCreate()
 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;
 }

© 2007 All rights reserved by TEC-IT Datenverarbeitung GmbH
Generated on Tue Nov 27 14:28:03 2007 for TEC-IT TBarCode Library 8.0.0 with doxygen 1.5.3