home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / docfile.ms / mspgle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  4.2 KB  |  156 lines

  1. /*
  2.  *  M S P G L E . C
  3.  *
  4.  *  Code for implementing the GetLastError method of all store
  5.  *  objects.
  6.  *
  7.  *  Copyright 1992-1995 Microsoft Corporation.  All Rights Reserved.
  8.  */
  9.  
  10. #include "msp.h"
  11. #include "msprc.h"
  12.  
  13. /* Manifest constants */
  14.  
  15. #define STRING_MAX      128
  16.  
  17. /* Global variables */
  18.  
  19. /* The following array maps a string identifier (IDS) to status code */
  20. /* (SCODE).  The order of SCODEs in the array has an external        */
  21. /* dependency:  the order of elements in the array is dictated by    */
  22. /* the IDS definitions in msprc.h.  This implicit association must   */
  23. /* be maintained for the strings associated with string identifiers  */
  24. /* to make sense.  Thus, if either this structure or the one in      */
  25. /* msprc.h changes, the other must change to match it.               */
  26.  
  27. SCODE mpIdsScode[] =
  28. {
  29.     S_OK,
  30.     MAPI_E_NO_ACCESS,
  31.     E_NOINTERFACE,
  32.     E_INVALIDARG,
  33.     MAPI_E_CALL_FAILED,
  34.     MAPI_E_NOT_FOUND,
  35.     MAPI_E_NO_SUPPORT,
  36.     MAPI_W_ERRORS_RETURNED,
  37.     MAPI_W_PARTIAL_COMPLETION,
  38.     MAPI_E_BAD_CHARWIDTH,
  39.     MAPI_E_BAD_VALUE,
  40.     MAPI_E_BUSY,
  41.     MAPI_E_COLLISION,
  42.     MAPI_E_COMPUTED,
  43.     MAPI_E_CORRUPT_DATA,
  44.     MAPI_E_CORRUPT_STORE,
  45.     MAPI_E_DISK_ERROR,
  46.     MAPI_E_HAS_FOLDERS,
  47.     MAPI_E_HAS_MESSAGES,
  48.     MAPI_E_INVALID_ENTRYID,
  49.     MAPI_E_INVALID_OBJECT,
  50.     MAPI_E_LOGON_FAILED,
  51.     MAPI_E_NETWORK_ERROR,
  52.     MAPI_E_NON_STANDARD,
  53.     MAPI_E_NOT_ENOUGH_DISK,
  54.     MAPI_E_NOT_ENOUGH_MEMORY,
  55.     MAPI_E_NOT_ENOUGH_RESOURCES,
  56.     MAPI_E_NOT_IN_QUEUE,
  57.     MAPI_E_OBJECT_CHANGED,
  58.     MAPI_E_OBJECT_DELETED,
  59.     MAPI_E_STRING_TOO_LONG,
  60.     MAPI_E_SUBMITTED,
  61.     MAPI_E_TOO_BIG,
  62.     MAPI_E_UNABLE_TO_ABORT,
  63.     MAPI_E_UNCONFIGURED,
  64.     MAPI_E_UNEXPECTED_TYPE,
  65.     MAPI_E_UNKNOWN_FLAGS,
  66.     MAPI_E_USER_CANCEL,
  67.     MAPI_E_VERSION
  68. };
  69.  
  70. /*
  71.  *  Exported functions
  72.  */
  73.  
  74. /*
  75.  *  MapScodeSz
  76.  *
  77.  *  Purpose:
  78.  *      Look up an SCODE in a mapping of IDS <-> SCODE to find its
  79.  *      associated informational string and return it (with memory
  80.  *      allocated by this function) to the caller.
  81.  *
  82.  *  Arguments:
  83.  *      scArg       The SCODE to look up.
  84.  *      pims        Pointer to the message store object (where we
  85.  *                  obtain the memory allocation functions).
  86.  *      lppszError  Location in which to place an address to a
  87.  *                  newly allocated buffer containing the
  88.  *                  informational string associated with scArg.
  89.  *
  90.  *  Returns:
  91.  *      HRESULT
  92.  *
  93.  *  Side effects:
  94.  *      None.
  95.  *
  96.  *  Errors:
  97.  *      MAPI_E_NOT_ENOUGH_MEMORY    Could not allocate space for
  98.  *                                  the return string.
  99.  */
  100. HRESULT MapScodeSz(SCODE scArg, PIMS pims, LPTSTR * lppszError)
  101. {
  102.     HRESULT hr = hrSuccess;
  103.     SCODE sc = SUCCESS_SUCCESS;
  104.     UINT ui = 0;
  105.     UINT uiMax = 0;
  106.     LPTSTR szErr = NULL;
  107.     TCHAR rgch[STRING_MAX];
  108.  
  109.     AssertSz(lppszError, "Bad lppszError\n");
  110.  
  111.     /* Linear search in mpIdsScode for scArg.  When found, index is IDS. */
  112.  
  113.     uiMax = sizeof mpIdsScode / sizeof mpIdsScode[0];
  114.     for (ui = 0; ui < uiMax; ui++)
  115.     {
  116.         if (mpIdsScode[ui] == scArg)
  117.             break;
  118.     }
  119.  
  120.     /* If we didn't find the string, return a NULL string. */
  121.  
  122.     if (ui == uiMax)
  123.         rgch[0] = (TCHAR) 0;
  124.     else
  125.     {
  126.         /* Get the string from the resource.  Note:  the assumption that   */
  127.         /* rgch is large enough to hold the largest string that LoadString */
  128.         /* could return can be checked by looking at the resource strings  */
  129.         /* file, msp.rc                                                    */
  130.  
  131.         int iLS = 0;
  132.     
  133.         Assert(pims->pmsp);
  134.     
  135.         iLS = LoadString(pims->pmsp->hInst, ui, rgch, STRING_MAX);
  136.         AssertSz(iLS, "Unknown string identifier!");
  137.         AssertSz(iLS < STRING_MAX-1, "String resource truncated!");
  138.     }
  139.  
  140.     /* Allocate memory for return variable and set it */
  141.  
  142.     sc = LMAlloc(&pims->lmr, Cbtszsize(rgch), &szErr);
  143.     if (sc != S_OK)
  144.     {
  145.         hr = ResultFromScode(sc);
  146.         goto exit;
  147.     }
  148.  
  149.     lstrcpy(szErr, rgch);
  150.     *lppszError = szErr;
  151.  
  152. exit:
  153.     DebugTraceResult(MapScodeSz, hr);
  154.     return hr;
  155. }
  156.