home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / mapi / win16 / dev / smh / smhoof.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  4.7 KB  |  171 lines

  1. /*
  2.  *  S M H O O F . C
  3.  *
  4.  *  Sample mail handling hook
  5.  *  Out of office management
  6.  *
  7.  *  Copyright 1992-95 Microsoft Corporation.  All Rights Reserved.
  8.  */
  9.  
  10. #include "_pch.h"
  11. #include <mapiutil.h>
  12.  
  13. #ifdef WIN32
  14. #define szPlatform "32"
  15. #else
  16. #define szPlatform
  17. #endif
  18.  
  19. enum { ipRID, ipREID, cpOofMax };
  20. static const TCHAR rgchITable[] = "MAPIU" szPlatform ".DLL";
  21. static const TCHAR rgchITableCreate[] = "CreateTable";
  22. typedef SCODE (STDMETHODCALLTYPE FAR * LPITABLECREATETABLE) (
  23.     LPCIID                  lpInterface,
  24.     ALLOCATEBUFFER FAR *    lpAllocateBuffer,
  25.     ALLOCATEMORE FAR *      lpAllocateMore,
  26.     FREEBUFFER FAR *        lpFreeBuffer,
  27.     LPVOID                  lpvReserved,
  28.     ULONG                   ulTableType,
  29.     ULONG                   ulPropTagIndexColumn,
  30.     LPSPropTagArray         lpSPropTagArrayColumns,
  31.     LPTABLEDATA FAR *       lppTableData);
  32.  
  33.  
  34. VOID
  35. ReleaseOof (LPOOF lpoof)
  36. {
  37.     if (lpoof->hlib)
  38.     {
  39.         UlRelease (lpoof->lptbl);
  40.         UlRelease (lpoof->lptad);
  41.         FreeLibrary (lpoof->hlib);
  42.     }
  43.     memset (lpoof, 0, sizeof(OOF));
  44.     return;
  45. }
  46.  
  47.  
  48. HRESULT
  49. HrLoadITable (LPOOF lpoof, LPITABLECREATETABLE FAR * lppfnCreateTable)
  50. {
  51.     UINT fuErr;
  52.     HINSTANCE hlib = lpoof->hlib;
  53.  
  54.     if (!hlib)
  55.     {
  56.         fuErr = SetErrorMode(SEM_NOOPENFILEERRORBOX);
  57.         hlib = LoadLibraryA (rgchITable);
  58.         SetErrorMode (fuErr);
  59.  
  60. #ifdef  WIN32
  61.         if(!hlib)
  62.         {
  63.             DebugTrace ("HrLoadITable() failed to load '%s'\n", rgchITable);
  64.             DebugTrace ("GetLastError() returns %ld\n", GetLastError());
  65.             DebugTraceSc (HrLoadITable(), MAPI_E_CALL_FAILED);
  66.             return ResultFromScode (MAPI_E_CALL_FAILED);
  67.         }
  68. #else
  69.         if(hlib <= HINSTANCE_ERROR)
  70.         {
  71.             DebugTrace ("HrLoadITable() failed to load '%s'\n", rgchITable);
  72.             DebugTrace ("LoadLibrary() returns %ld\n", hlib);
  73.             DebugTraceSc (HrLoadITable(), MAPI_E_CALL_FAILED);
  74.             return ResultFromScode (MAPI_E_CALL_FAILED);
  75.         }
  76. #endif
  77.  
  78.         *lppfnCreateTable = (LPITABLECREATETABLE) GetProcAddress (hlib, rgchITableCreate);
  79.         if (!*lppfnCreateTable)
  80.         {
  81.             DebugTrace ("HrLoadITable() failed to find create table API\n");
  82.             DebugTraceSc (HrLoadITable(), MAPI_E_CALL_FAILED);
  83.             return ResultFromScode (MAPI_E_CALL_FAILED);
  84.         }
  85.         
  86.         lpoof->hlib = hlib;
  87.     }
  88.     return S_OK;
  89. }
  90.  
  91.  
  92. BOOL
  93. FOofRecip (LPOOF lpoof, LPSPropValue lpvalEid)
  94. {
  95.     BOOL fOof = TRUE;
  96.     LPMAPITABLE lptbl = lpoof->lptbl;
  97.     SPropValue val;
  98.     SRestriction res;
  99.  
  100.     if (lptbl)
  101.     {
  102.         val.ulPropTag = PR_ENTRYID;
  103.         val.Value = lpvalEid->Value;
  104.  
  105.         res.rt = RES_PROPERTY;
  106.         res.res.resProperty.relop = RELOP_EQ;
  107.         res.res.resProperty.ulPropTag = PR_ENTRYID;
  108.         res.res.resProperty.lpProp = &val;
  109.  
  110.         fOof = !!HR_FAILED (lptbl->lpVtbl->FindRow (lptbl, &res, BOOKMARK_BEGINNING, 0L));
  111.     }
  112.     return fOof;
  113. }
  114.  
  115.  
  116. HRESULT
  117. HrRegOofRecip (LPSMH lpsmh, LPOOF lpoof, LPSPropValue lpvalEid)
  118. {
  119.     HRESULT hr;
  120.     LPTABLEDATA lptad = lpoof->lptad;
  121.     SizedSPropTagArray (cpOofMax, sptOofTbl) = {cpOofMax, { PR_ROWID, PR_ENTRYID }};
  122.     SPropValue rgval[cpOofMax];
  123.     SRow rw;
  124.  
  125.     if (!lptad)
  126.     {
  127.         LPITABLECREATETABLE lpfnCreateTable = NULL;
  128.         
  129.         //  This is the first OOF recip so we need to create the
  130.         //  table of recips
  131.         //
  132.         hr = HrLoadITable (lpoof, &lpfnCreateTable);
  133.         if (HR_FAILED (hr))
  134.             goto ret;
  135.  
  136.         hr = ResultFromScode ((*lpfnCreateTable) ((LPIID)&IID_IMAPITableData,
  137.                             lpsmh->lpfnAlloc,
  138.                             lpsmh->lpfnAllocMore,
  139.                             lpsmh->lpfnFree,
  140.                             NULL,
  141.                             TBLTYPE_DYNAMIC,
  142.                             PR_ROWID,
  143.                             (LPSPropTagArray)&sptOofTbl,
  144.                             (LPTABLEDATA FAR *)&lptad));
  145.         if (HR_FAILED (hr))
  146.             goto ret;
  147.         
  148.         hr = lptad->lpVtbl->HrGetView (lptad, NULL, NULL, 0, &lpoof->lptbl);
  149.         if (!HR_FAILED (hr))
  150.         {
  151.             UlRelease (lptad);
  152.             goto ret;
  153.         }
  154.         lpoof->lptad = lptad;
  155.     }
  156.     
  157.     rgval[ipRID].ulPropTag = PR_ROWID;
  158.     rgval[ipRID].Value.l = lpoof->cRecips++;
  159.     rgval[ipREID].ulPropTag = PR_ENTRYID;
  160.     rgval[ipREID].Value = lpvalEid->Value;
  161.  
  162.     hr = lptad->lpVtbl->HrModifyRow (lptad, &rw);
  163.     if (HR_FAILED (hr))
  164.         goto ret;
  165.  
  166. ret:
  167.  
  168.     DebugTraceResult (HrRegOofRecip(), hr);
  169.     return hr;
  170. }
  171.