#include "stdafx.h"
#include "BioAPI20_Util.h"


void GetBioAPIErrorDescription(BioAPI_RETURN ret, LPTSTR szDescription, DWORD nMaxLen)
{
   if (!szDescription)
     return;

   memset(szDescription, 0, nMaxLen);

   TCHAR szDesc[256] = _T("");
   switch (ret)
   {
      case BioAPI_OK:
         lstrcpy(szDesc, _T("The operation completed successfully."));
         break;

      case BioAPIERR_INTERNAL_ERROR:
         lstrcpy(szDesc, _T("General system error: an operating system or internal state error has occurred and the system may not be in a known state."));
         break;

      case BioAPIERR_MEMORY_ERROR:
         lstrcpy(szDesc, _T("A memory error occurred."));
         break;

      case BioAPIERR_INVALID_POINTER:
         lstrcpy(szDesc, _T("An input/output function parameter or input/output field inside of a data structure is an invalid pointer."));
         break;

      case BioAPIERR_INVALID_INPUT_POINTER:
         lstrcpy(szDesc, _T("An input function parameter or input field in a data structure is an invalid pointer."));
         break;

      case BioAPIERR_INVALID_OUTPUT_POINTER:
         lstrcpy(szDesc, _T("An output function parameter or output field in a data structure is an invalid pointer."));
         break;

      case BioAPIERR_FUNCTION_NOT_SUPPORTED:
         lstrcpy(szDesc, _T("The function is not implemented by the service provider."));
         break;

      case BioAPIERR_OS_ACCESS_DENIED:
         lstrcpy(szDesc, _T("The operating system denied access to a required resource."));
         break;

      case BioAPIERR_FUNCTION_FAILED:
         lstrcpy(szDesc, _T("The function failed for an unknown reason."));
         break;

      case BioAPIERR_INVALID_UUID:
         lstrcpy(szDesc, _T("Invalid UUID."));
         break;

      case BioAPIERR_INCOMPATIBLE_VERSION:
         lstrcpy(szDesc, _T("Version incompatibility."));
         break;

      case BioAPIERR_INVALID_DATA:
         lstrcpy(szDesc, _T("The data in an input parameter is invalid."));
         break;

      case BioAPIERR_UNABLE_TO_CAPTURE:
         lstrcpy(szDesc, _T("The associated BSP is unable to capture raw samples from the requested device."));
         break;

      case BioAPIERR_TOO_MANY_HANDLES:
         lstrcpy(szDesc, _T("The framework has no more space to allocate attachment handles or the associated BSP has no more space to allocate BIR handles."));
         break;

      case BioAPIERR_TIMEOUT_EXPIRED:
         lstrcpy(szDesc, _T("The function has been terminated because the timeout value has expired."));
         break;

      case BioAPIERR_INVALID_BIR:
         lstrcpy(szDesc, _T("The input BIR is invalid for the purpose required."));
         break;

      case BioAPIERR_BIR_SIGNATURE_FAILURE:
         lstrcpy(szDesc, _T("The associated BSP could not validate the signature on the BIR."));
         break;

      case BioAPIERR_UNABLE_TO_STORE_PAYLOAD:
         lstrcpy(szDesc, _T("The associated BSP is unable to store the payload."));
         break;

      case BioAPIERR_NO_INPUT_BIRS:
         lstrcpy(szDesc, _T("The identify population is NULL."));
         break;

      case BioAPIERR_UNSUPPORTED_FORMAT:
         lstrcpy(szDesc, _T("The associated BSP does not support the BDB format."));
         break;

      case BioAPIERR_UNABLE_TO_IMPORT:
         lstrcpy(szDesc, _T("The associated BSP was unable to construct a BIR from the input data."));
         break;

      case BioAPIERR_INCONSISTENT_PURPOSE:
         lstrcpy(szDesc, _T("The purpose recorded in the BIR and the requested purpose are inconsistent with the function being performed."));
         break;

      case BioAPIERR_BIR_NOT_FULLY_PROCESSED:
         lstrcpy(szDesc, _T("The function requires a fully processed BIR."));
         break;

      case BioAPIERR_PURPOSE_NOT_SUPPORTED:
         lstrcpy(szDesc, _T("The BSP does not support the requested purpose."));
         break;

      case BioAPIERR_USER_CANCELLED:
         lstrcpy(szDesc, _T("User cancelled operation before completion or timeout."));
         break;

      case BioAPIERR_UNIT_IN_USE:
         lstrcpy(szDesc, _T("BSP (or BioAPI Unit attached to BSP) is currently being used by another biometric application."));
         break;

      case BioAPIERR_INVALID_BSP_HANDLE:
         lstrcpy(szDesc, _T("The given BSP handle is not valid."));
         break;

      case BioAPIERR_FRAMEWORK_NOT_INITIALIZED:
         lstrcpy(szDesc, _T("A function has been called without initializing the BioAPI Framework."));
         break;

      case BioAPIERR_INVALID_BIR_HANDLE:
         lstrcpy(szDesc, _T("BIR handle is invalid (does not exist or has been released)."));
         break;

      case BioAPIERR_CALIBRATION_NOT_SUCCESSFUL:
         lstrcpy(szDesc, _T("The attempted calibration of a sensor unit was not able to be successfully completed."));
         break;

      case BioAPIERR_PRESET_BIR_DOES_NOT_EXIST:
         lstrcpy(szDesc, _T("No preset BIR population has been established."));
         break;

      case BioAPIERR_BIR_DECRYPTION_FAILURE:
         lstrcpy(szDesc, _T("The BSP could not decrypt an input BIR (and thus was unable to use it for the requested operation)."));
         break;

      case BioAPIERR_COMPONENT_FILE_REF_NOT_FOUND:
         lstrcpy(szDesc, _T("A reference to the component file cannot be obtained."));
         break;

      case BioAPIERR_BSP_LOAD_FAIL:
         lstrcpy(szDesc, _T("Framework was unable to successfully load the BSP."));
         break;

      case BioAPIERR_BSP_NOT_LOADED:
         lstrcpy(szDesc, _T("BSP for which an action was requested is not loaded."));
         break;

      case BioAPIERR_UNIT_NOT_INSERTED:
         lstrcpy(szDesc, _T("BioAPI Unit for which an action was requested is not in the inserted state."));
         break;

      case BioAPIERR_INVALID_UNIT_ID:
         lstrcpy(szDesc, _T("An invalid BioAPI Unit ID was requested."));
         break;

      case BioAPIERR_INVALID_CATEGORY:
         lstrcpy(szDesc, _T("An invalid category of BFP or BioAPI Unit was requested."));
         break;

      case BioAPIERR_INVALID_DB_HANDLE:
         lstrcpy(szDesc, _T("Invalid database handle."));
         break;

      case BioAPIERR_UNABLE_TO_OPEN_DATABASE:
         lstrcpy(szDesc, _T("The associated BSP is unable to open the specified database."));
         break;

      case BioAPIERR_DATABASE_IS_LOCKED:
         lstrcpy(szDesc, _T("The database cannot be opened for the access requested because it is locked."));
         break;

      case BioAPIERR_DATABASE_DOES_NOT_EXIST:
         lstrcpy(szDesc, _T("The specified database does not exist."));
         break;

      case BioAPIERR_DATABASE_ALREADY_EXISTS:
         lstrcpy(szDesc, _T("Create failed because the database already exists."));
         break;

      case BioAPIERR_INVALID_DATABASE_NAME:
         lstrcpy(szDesc, _T("Invalid database name."));
         break;

      case BioAPIERR_RECORD_NOT_FOUND:
         lstrcpy(szDesc, _T("No record exists with the requested key."));
         break;

      case BioAPIERR_MARKER_HANDLE_IS_INVALID:
         lstrcpy(szDesc, _T("The specified marker handle is invalid."));
         break;

      case BioAPIERR_DATABASE_IS_OPEN:
         lstrcpy(szDesc, _T("The database is already open."));
         break;

      case BioAPIERR_INVALID_ACCESS_REQUEST:
         lstrcpy(szDesc, _T("Unrecognized access type."));
         break;

      case BioAPIERR_END_OF_DATABASE:
         lstrcpy(szDesc, _T("End of database has been reached."));
         break;

      case BioAPIERR_UNABLE_TO_CREATE_DATABASE:
         lstrcpy(szDesc, _T("The associated BSP cannot create the database."));
         break;

      case BioAPIERR_UNABLE_TO_CLOSE_DATABASE:
         lstrcpy(szDesc, _T("The associated BSP cannot close the database."));
         break;

      case BioAPIERR_UNABLE_TO_DELETE_DATABASE:
         lstrcpy(szDesc, _T("The associated BSP cannot delete the database."));
         break;

      case BioAPIERR_DATABASE_IS_CORRUPT:
         lstrcpy(szDesc, _T("The specified database is corrupt."));
         break;

      case BioAPIERR_LOCATION_ERROR:
         lstrcpy(szDesc, _T("A general location error."));
         break;

      case BioAPIERR_OUT_OF_FRAME:
         lstrcpy(szDesc, _T("Invalid horizontal or vertical position."));
         break;

      case BioAPIERR_INVALID_CROSSWISE_POSITION:
         lstrcpy(szDesc, _T("Invalid crosswise position."));
         break;

      case BioAPIERR_INVALID_LENGTHWISE_POSITION:
         lstrcpy(szDesc, _T("Invalid lengthwise position."));
         break;

      case BioAPIERR_INVALID_DISTANCE:
         lstrcpy(szDesc, _T("Invalid distance."));
         break;

      case BioAPIERR_LOCATION_TOO_RIGHT:
         lstrcpy(szDesc, _T("The position was too far to the right."));
         break;

      case BioAPIERR_LOCATION_TOO_LEFT:
         lstrcpy(szDesc, _T("The position was too far to the left."));
         break;

      case BioAPIERR_LOCATION_TOO_HIGH:
         lstrcpy(szDesc, _T("The position was too high."));
         break;

      case BioAPIERR_LOCATION_TOO_LOW:
         lstrcpy(szDesc, _T("The position was too low."));
         break;

      case BioAPIERR_LOCATION_TOO_FAR:
         lstrcpy(szDesc, _T("The position was too far away."));
         break;

      case BioAPIERR_LOCATION_TOO_NEAR:
         lstrcpy(szDesc, _T("The position was too near (close)."));
         break;

      case BioAPIERR_LOCATION_TOO_FORWARD:
         lstrcpy(szDesc, _T("The position was too far forward."));
         break;

      case BioAPIERR_LOCATION_TOO_BACKWARD:
         lstrcpy(szDesc, _T("The position was too far backward."));
         break;

      case BioAPIERR_QUALITY_ERROR:
         lstrcpy(szDesc, _T("Sample quality is too poor for the operation to succeed."));
         break;

      default:
         lstrcpy(szDesc, _T("Unknown Error"));
         break;
   }

   lstrcpyn(szDescription, szDesc, nMaxLen);
}
