home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / 32ADDRES.PAK / MACRO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  103 lines

  1. // BDE32 3.x - (C) Copyright 1996 by Borland International
  2.  
  3. #include "address.h"  
  4.  
  5. //      The way to use this macro is to include the macro.h header
  6. //      file where you want to use this function. Then pass an IDAPI
  7. //      function as a parameter to the macro:
  8. //
  9. //      #define CHKERR(parm) DBIError(__FILE__, __LINE__, \    //
  10. //                                    #parm, parm) ; \          //
  11. //                                    if ( GlobalDBIErr ) { \   //
  12. //                                        return GlobalDBIErr ;}
  13. //
  14. //      For Example:
  15. //          CHKERR(DbiCreateTable(hDb, bOverWrite, &crTblDsc)) ;
  16.  
  17. DBIResult GlobalDBIErr;
  18. static char szDBIStatus[(DBIMAXMSGLEN * 7)+1];
  19.  
  20. // Leave space for the extra messages.
  21. static char szMessage[(DBIMAXMSGLEN * 7)+1+110];
  22. //====================================================================
  23. //  Name:   DBIError();
  24. //
  25. //  Input:  module name (pCHAR), line number (UINT16), Engine function
  26. //          name (pCHAR), Result (DBIResult)
  27. //
  28. //  Return: A DBIResult value.
  29. //
  30. //  Description:
  31. //          This is function that takes in the information of where
  32. //          the error accured and displays that is a message box.
  33. //          The information listed above explains how to use this
  34. //          function inside of a macro.
  35. //====================================================================
  36. DBIResult
  37. DBIError (pCHAR module, UINT16 line, pCHAR function, DBIResult retVal)
  38. {
  39.     DBIErrInfo  ErrInfo;
  40.  
  41.     if (retVal == DBIERR_NONE)
  42.     {
  43.         GlobalDBIErr = DBIERR_NONE;
  44.         return retVal;
  45.     }
  46.     if (retVal != DBIERR_CANTFINDODAPI)
  47.     {
  48.         // Get as much error information as possible
  49.         DbiGetErrorInfo(TRUE, &ErrInfo);
  50.  
  51.         // Make certain information is returned on the correct error
  52.         if (ErrInfo.iError == retVal)
  53.         {
  54.             strcpy(szDBIStatus, ErrInfo.szErrCode);
  55.  
  56.             if (strcmp(ErrInfo.szContext1, ""))
  57.             {
  58.                 strcat(szDBIStatus, ErrInfo.szContext1);
  59.             }
  60.             if (strcmp(ErrInfo.szContext2, ""))
  61.             {
  62.                 strcat(szDBIStatus, ErrInfo.szContext2);
  63.             }
  64.             if (strcmp(ErrInfo.szContext3, ""))
  65.             {
  66.                 strcat(szDBIStatus, ErrInfo.szContext3);
  67.             }
  68.             if (strcmp(ErrInfo.szContext4, ""))
  69.             {
  70.                 strcat(szDBIStatus, ErrInfo.szContext4);
  71.             }
  72.         }
  73.         else {
  74.             DbiGetErrorString(retVal, szDBIStatus);
  75.         }
  76.  
  77.         sprintf(szMessage, "Module:\t\t%s\nFunction:\t%s\nLine:\t\t%d\n"
  78.                 "Category:\t%d\nCode:\t\t%d\nError:\r\n\r\n%s", module,
  79.                 function, line, ErrCat(retVal), ErrCode(retVal),
  80.                 szDBIStatus);
  81.  
  82.         MessageBox(hErrorWnd, szMessage, "AddressBook Error",
  83.                    MB_ICONEXCLAMATION);
  84.  
  85.         // Finally set focus to the First name edit control.
  86.         if(hErrorWnd == hMainWnd)
  87.         {
  88.             SetFNameFocus();
  89.         }
  90.         else
  91.         {
  92.             PostMessage(hErrorWnd, WM_SETFOCUS,0,0L);
  93.         }
  94.     }
  95.     else
  96.     {
  97.         MessageBox(NULL, "Cannot find IDAPI files: Check path.",
  98.                    "IDAPI Initialization Error", MB_ICONHAND | MB_OK);
  99.     }
  100.     GlobalDBIErr = retVal;
  101.     return retVal;
  102. }
  103.