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 / flatfile.ab / abctbl3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  21.9 KB  |  999 lines

  1. /***********************************************************************
  2.  *
  3.  *  ABCTBL3.C
  4.  *
  5.  *  Contents Table - Part 3.
  6.  *
  7.  *
  8.  *  The following routines are implemented in this file.
  9.  *
  10.  *
  11.  *      IVTABC_QueryInterface
  12.  *      IVTABC_Release
  13.  *      IVTABC_SortTable
  14.  *      IVTABC_QuerySortOrder
  15.  *      IVTABC_CreateBookmark
  16.  *      IVTABC_FreeBookmark
  17.  *      IVTABC_ExpandRow
  18.  *      IVTABC_ColapseRow
  19.  *      IVTABC_WaitForCompletion
  20.  *      IVTABC_Abort
  21.  *      IVTABC_Advise
  22.  *      IVTABC_Unadvise
  23.  *      IVTABC_GetStatus
  24.  *      IVTABC_SetColumns
  25.  *      IVTABC_QueryColumns
  26.  *      IVTABC_GetCollapseState,
  27.  *      IVTABC_SetCollapseState,
  28.  *
  29.  *  Copyright 1992-1995 Microsoft Corporation.  All Rights Reserved.
  30.  *
  31.  ***********************************************************************/
  32.  
  33.  
  34.  
  35.  
  36.  
  37. #include "abp.h"
  38. #include "abctbl.h"
  39. #include "sampabp.rh"
  40.  
  41.  
  42. /*
  43.  *  Default sort order set
  44.  */
  45. static const SizedSSortOrderSet(1, sosIVTABC) =
  46. {
  47.     1,
  48.     0,
  49.     0,
  50.     {
  51.         {
  52.             PR_DISPLAY_NAME_A, TABLE_SORT_ASCEND
  53.         }
  54.     }
  55. };
  56.  
  57.  
  58.  
  59.  
  60. /*************************************************************************
  61.  *
  62.  *
  63.  -  AVTABC_QueryInterface
  64.  -
  65.  *
  66.  *
  67.  *
  68.  */
  69. STDMETHODIMP 
  70. IVTABC_QueryInterface(LPIVTABC lpIVTAbc,
  71.     REFIID lpiid,
  72.     LPVOID FAR * lppNewObj)
  73. {
  74.  
  75.     HRESULT hResult = hrSuccess;
  76.  
  77.     IVTABC_ValidateObject(QueryInterface, lpIVTAbc);
  78.  
  79.     Validate_IUnknown_QueryInterface(lpIVTAbc, lpiid, lppNewObj);
  80.  
  81.     
  82.     /*  See if the requested interface is one of ours */
  83.  
  84.     if (memcmp(lpiid, &IID_IUnknown, sizeof(IID)) &&
  85.         memcmp(lpiid, &IID_IMAPITable, sizeof(IID)))
  86.     {
  87.         *lppNewObj = NULL;      /* OLE requires zeroing the [out] parameter */
  88.         DebugTraceSc(IVTABC_QueryInterface, E_NOINTERFACE);
  89.         return ResultFromScode(E_NOINTERFACE);
  90.     }
  91.  
  92.     /*  We'll do this one. Bump the usage count and return a new pointer. */
  93.  
  94.     EnterCriticalSection(&lpIVTAbc->cs);
  95.     ++lpIVTAbc->lcInit;
  96.     LeaveCriticalSection(&lpIVTAbc->cs);
  97.     
  98.     *lppNewObj = lpIVTAbc;
  99.  
  100.     DebugTraceResult(IVTABC_QueryInterface,hResult);
  101.     return hResult;
  102. }
  103.  
  104. /*************************************************************************
  105.  *
  106.  -  IVTABC_Release
  107.  -
  108.  *
  109.  *      Decrement the reference count on this object and free it if
  110.  *      the reference count is zero.
  111.  *      Returns the reference count.
  112.  */
  113.  
  114. STDMETHODIMP_(ULONG)
  115. IVTABC_Release(LPIVTABC lpIVTAbc)
  116. {
  117.     ULONG ulBK;
  118.     long lcInit;
  119.     
  120.     /*
  121.      *  Check to see if it's big enough to hold this object
  122.      */
  123.     if (IsBadReadPtr(lpIVTAbc, sizeof(IVTABC)))
  124.     {
  125.         /*
  126.          *  Not large enough
  127.          */
  128.         return 1;
  129.     }
  130.  
  131.     /*
  132.      *  Check to see that it's the correct vtbl
  133.      */
  134.     if (lpIVTAbc->lpVtbl != &vtblIVTABC)
  135.     {
  136.         /*
  137.          *  Not my vtbl
  138.          */
  139.         return 1;
  140.     }
  141.  
  142.     Validate_IUnknown_Release(lpIVTAbc);
  143.  
  144.  
  145.     EnterCriticalSection(&lpIVTAbc->cs);
  146.     lcInit = --lpIVTAbc->lcInit;
  147.     LeaveCriticalSection(&lpIVTAbc->cs);
  148.  
  149.     if (lcInit == 0)
  150.     {
  151.         /*
  152.          *  Free up the current column set
  153.          */
  154.         if (lpIVTAbc->lpPTAColSet != ptagaivtabcColSet)
  155.         {
  156.             lpIVTAbc->lpFreeBuff (lpIVTAbc->lpPTAColSet);
  157.         }
  158.  
  159.         /*
  160.          *  Close up the file
  161.          */
  162.         if (lpIVTAbc->hFile != INVALID_HANDLE_VALUE)
  163.         {
  164.             CloseHandle(lpIVTAbc->hFile);
  165.             lpIVTAbc->hFile = INVALID_HANDLE_VALUE;
  166.         }
  167.  
  168.         /*
  169.          *  Free up the file name
  170.          */
  171.         lpIVTAbc->lpFreeBuff(lpIVTAbc->lpszFileName);
  172.  
  173.         /*
  174.          *  Rip through the bookmarks and free up any that are there
  175.          */
  176.         for (ulBK = 0; ulBK < MAX_BOOKMARKS; ulBK++)
  177.             if (lpIVTAbc->rglpABCBK[ulBK])
  178.             {
  179.                 (*(lpIVTAbc->lpFreeBuff)) (lpIVTAbc->rglpABCBK[ulBK]);
  180.                 lpIVTAbc->rglpABCBK[ulBK] = NULL;
  181.             }
  182.  
  183.         /*
  184.          *  Free up the ANR stuff, if used
  185.          */
  186.         lpIVTAbc->lpFreeBuff (lpIVTAbc->lpszPartialName);
  187.  
  188.         FreeANRBitmaps(lpIVTAbc);
  189.  
  190.         /*
  191.          *  Free up the advise list, if used
  192.          */
  193.         if (lpIVTAbc->parglpAdvise)
  194.             lpIVTAbc->lpMalloc->lpVtbl->Free(lpIVTAbc->lpMalloc, lpIVTAbc->parglpAdvise);
  195.  
  196.         /*  
  197.          *  Release our reference to the ABLogon object.
  198.          */
  199.         if (lpIVTAbc->lpABLogon)
  200.         {
  201.             lpIVTAbc->lpABLogon->lpVtbl->Release(lpIVTAbc->lpABLogon);
  202.             lpIVTAbc->lpABLogon = NULL;
  203.         }
  204.  
  205.         /* Delete critical section for this object */
  206.         DeleteCriticalSection(&lpIVTAbc->cs);
  207.  
  208.         /* Deregister the idle routine */
  209.  
  210.         DeregisterIdleRoutine(lpIVTAbc->ftg);
  211.  
  212.         /*
  213.          *  Set the vtbl to NULL.  This way the client will find out
  214.          *  real fast if it's calling a method on a released object.  That is,
  215.          *  the client will crash.  Hopefully, this will happen during the
  216.          *  development stage of the client.
  217.          */
  218.         lpIVTAbc->lpVtbl = NULL;
  219.  
  220.         /*
  221.          *  Need to free the object
  222.          */
  223.  
  224.         lpIVTAbc->lpFreeBuff(lpIVTAbc);
  225.         return 0;
  226.     }
  227.  
  228.     return lcInit;
  229. }
  230.  
  231.  
  232.  
  233. /*
  234.  -  IVTABC_SortTable
  235.  -
  236.  *  The Sample Address Book does not resort it's views.
  237.  *
  238.  */
  239. STDMETHODIMP 
  240. IVTABC_SortTable(LPIVTABC lpIVTAbc,
  241.     LPSSortOrderSet lpSortCriteria,
  242.     ULONG ulFlags)
  243. {
  244.     HRESULT hResult;
  245.  
  246.     /*
  247.      *  Validate parameters
  248.      */
  249.     IVTABC_ValidateObject(SortTable, lpIVTAbc);
  250.     
  251.     Validate_IMAPITable_SortTable(lpIVTAbc, lpSortCriteria, ulFlags);
  252.  
  253.  
  254.     /*
  255.      *  We don't support sorting this table
  256.      */
  257.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  258.  
  259.     DebugTraceResult(IVTABC_SortTable, hResult);
  260.     return hResult;
  261.  
  262. }
  263.  
  264. /*
  265.  -  IVTABC_QuerySortOrder
  266.  -
  267.  *
  268.  *  For this implementation there is only one sort order
  269.  */
  270.  
  271. STDMETHODIMP 
  272. IVTABC_QuerySortOrder(LPIVTABC lpIVTAbc,
  273.     LPSSortOrderSet * lppSortCriteria)
  274. {
  275.     SCODE scode;
  276.     HRESULT hResult = hrSuccess;
  277.     int cbSize;
  278.  
  279.     /*
  280.      *  Validate parameters
  281.      */
  282.  
  283.     IVTABC_ValidateObject(QuerySortOrder, lpIVTAbc);
  284.  
  285.     Validate_IMAPITable_QuerySortOrder(lpIVTAbc, lppSortCriteria);
  286.  
  287.  
  288.     /*  Calculate size of the structure we're gonna copy */
  289.     cbSize = CbNewSSortOrderSet((int)sosIVTABC.cSorts);
  290.  
  291.     scode = lpIVTAbc->lpAllocBuff(cbSize, (LPVOID *) lppSortCriteria);
  292.     if (FAILED(scode))
  293.     {
  294.         hResult = ResultFromScode(scode);
  295.  
  296.         goto out;
  297.     }
  298.  
  299.     /*
  300.      *  Copy the column set in
  301.      */
  302.     if (cbSize)
  303.         memcpy(*lppSortCriteria, &sosIVTABC, cbSize);
  304.  
  305. out:
  306.  
  307.     DebugTraceResult(IVTABC_QuerySortOrder, hResult);
  308.     return hResult;
  309.  
  310. }
  311.  
  312.  
  313.  
  314.  
  315. /*
  316.  -  IVTABC_CreateBookmark
  317.  -
  318.  *  Creates a bookmark associated with a row in a table
  319.  *
  320.  */
  321. STDMETHODIMP 
  322. IVTABC_CreateBookmark(LPIVTABC lpIVTAbc,
  323.     BOOKMARK * lpbkPosition)
  324. {
  325.     SCODE scode;
  326.     HRESULT hResult = hrSuccess;
  327.     ULONG ulBK;
  328.     LPABCBK lpABCBK = NULL;
  329.     ULONG cbRead = 0;
  330.  
  331.     /*
  332.      *  Validate parameters
  333.      */
  334.  
  335.     IVTABC_ValidateObject(CreateBookmark, lpIVTAbc);
  336.  
  337.     Validate_IMAPITable_CreateBookmark(lpIVTAbc, lpbkPosition);
  338.  
  339.  
  340.     EnterCriticalSection(&lpIVTAbc->cs);
  341.  
  342.  
  343.     /*
  344.      *  Open the file
  345.      */
  346.     hResult = HrOpenFile(lpIVTAbc);
  347.     if (HR_FAILED(hResult))
  348.     {
  349.         goto out;
  350.     }
  351.  
  352.     /*
  353.      *  Shortcuts first
  354.      */
  355.     if (lpIVTAbc->ulPosition == lpIVTAbc->ulMaxPos)
  356.     {
  357.         *lpbkPosition = BOOKMARK_END;
  358.         return hrSuccess;
  359.     }
  360.  
  361.     /*
  362.      *  search for a blank bookmark
  363.      */
  364.     for (ulBK = 0; lpIVTAbc->rglpABCBK[ulBK] && ulBK < MAX_BOOKMARKS; ulBK++);
  365.  
  366.     /*  did we find any??  */
  367.     if (ulBK == MAX_BOOKMARKS)
  368.     {
  369.         hResult = ResultFromScode(MAPI_E_UNABLE_TO_COMPLETE);
  370.  
  371.         goto out;
  372.     }
  373.  
  374.  
  375.     scode = lpIVTAbc->lpAllocBuff (sizeof(ABCBK),(LPVOID *) &lpABCBK);
  376.     if (FAILED(scode))
  377.     {
  378.         hResult = ResultFromScode(scode);
  379.         goto out;
  380.     }
  381.  
  382.     /*
  383.      *  Fill in new bookmark
  384.      */
  385.     lpABCBK->filetime = lpIVTAbc->filetime;
  386.     lpABCBK->ulPosition = lpIVTAbc->ulPosition;
  387.  
  388.     /*  Seek to position in file  */
  389.     (void) SetFilePointer(lpIVTAbc->hFile, lpABCBK->ulPosition, NULL, FILE_BEGIN);
  390.  
  391.     /*  Read in the record at that location  */
  392.     if (!ReadFile(lpIVTAbc->hFile,
  393.             (LPVOID) &(lpABCBK->abcrec), sizeof(ABCREC), &cbRead, NULL))
  394.     {
  395.         goto readerror;
  396.     }
  397.     /*  Second check  */
  398.     if (cbRead != sizeof(ABCREC))
  399.     {
  400.         goto readerror;
  401.     }
  402.  
  403.     /*
  404.      *  Put this in the bookmark structure
  405.      */
  406.     lpIVTAbc->rglpABCBK[ulBK] = lpABCBK;
  407.  
  408.     /*  Return the bookmark  */
  409.     *lpbkPosition = ulBK + 3;
  410.  
  411. out:
  412.     LeaveCriticalSection(&lpIVTAbc->cs);
  413.  
  414.     DebugTraceResult(IVTABC_CreateBookmark, hResult);
  415.     return hResult;
  416.  
  417. readerror:
  418.     /*
  419.      *  Didn't get the record.
  420.      */
  421.  
  422.     /*  Restore back to original position  */
  423.     (void) SetFilePointer(lpIVTAbc->hFile, lpIVTAbc->ulPosition, NULL, FILE_BEGIN);
  424.  
  425.     /*  Free up the new bookmark  */
  426.     lpIVTAbc->lpFreeBuff(lpABCBK);
  427.  
  428.     hResult = ResultFromScode(MAPI_E_UNABLE_TO_COMPLETE);
  429.     SetErrorIDS(lpIVTAbc, hResult, IDS_SAB_NO_READ);
  430.  
  431.     goto out;
  432. }
  433.  
  434. /*************************************************************************
  435.  *
  436.  -  IVTABC_FreeBookmark
  437.  -
  438.  *  Frees up the given bookmark
  439.  *
  440.  *
  441.  *
  442.  */
  443. STDMETHODIMP 
  444. IVTABC_FreeBookmark(LPIVTABC lpIVTAbc,
  445.     BOOKMARK bkPosition)
  446. {
  447.     HRESULT hResult = hrSuccess;
  448.  
  449.     /*
  450.      *  Validate parameters
  451.      */
  452.  
  453.     IVTABC_ValidateObject(FreeBookmark, lpIVTAbc);
  454.  
  455.     Validate_IMAPITable_FreeBookmark(lpIVTAbc, bkPosition);
  456.  
  457.  
  458.     EnterCriticalSection(&lpIVTAbc->cs);
  459.  
  460.  
  461.     /*
  462.      *  Don't try and free up any of the standard bookmarks
  463.      */
  464.     if ((bkPosition != BOOKMARK_BEGINNING) &&
  465.         (bkPosition != BOOKMARK_CURRENT) &&
  466.         (bkPosition != BOOKMARK_END))
  467.     {
  468.         ULONG ulBK = (ULONG) bkPosition - 3;
  469.  
  470.         /*
  471.          *  See if it's in range
  472.          */
  473.         if (ulBK >= 0 && ulBK < MAX_BOOKMARKS)
  474.         {
  475.             LPABCBK lpABCBK = NULL;
  476.  
  477.             /*  If it's valid...  */
  478.             if (lpABCBK = lpIVTAbc->rglpABCBK[ulBK])    /* '=' on purpose */
  479.             {
  480.                 /*  ...free it up.  */
  481.  
  482.                 lpIVTAbc->lpFreeBuff(lpABCBK);
  483.                 lpIVTAbc->rglpABCBK[ulBK] = NULL;
  484.             }
  485.  
  486.         }
  487.         else
  488.         {
  489.             /*
  490.              * It's an error
  491.              */
  492.             hResult = ResultFromScode(E_INVALIDARG);
  493.  
  494.         }
  495.     }
  496.  
  497.     LeaveCriticalSection(&lpIVTAbc->cs);
  498.  
  499.     DebugTraceResult(IVTABC_FreeBookmark, hResult);
  500.     return hResult;
  501.  
  502. }
  503.  
  504.  
  505. /*************************************************************************
  506.  *
  507.  -  IVTABC_ExpandRow
  508.  -
  509.  *  Stubbed out.  This table doesn't implement catagorization.
  510.  *
  511.  *
  512.  *
  513.  */
  514. STDMETHODIMP 
  515. IVTABC_ExpandRow(LPIVTABC lpIVTAbc, ULONG cbIKey, LPBYTE pbIKey,
  516.     ULONG ulRowCount, ULONG ulFlags, LPSRowSet FAR * lppRows,
  517.     ULONG FAR * lpulMoreRows)
  518.  
  519. {
  520.     HRESULT hResult;
  521.  
  522.     /*
  523.      *  Validate parameters
  524.      */
  525.  
  526.     IVTABC_ValidateObject(ExpandRow, lpIVTAbc);
  527.  
  528.     Validate_IMAPITable_ExpandRow(lpIVTAbc,  cbIKey,  pbIKey,
  529.                             ulRowCount,  ulFlags,  lppRows, lpulMoreRows);
  530.  
  531.  
  532.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  533.  
  534.     DebugTraceResult(IVTABC_ExpandRow, hResult);
  535.     return hResult;
  536.  
  537. }
  538.  
  539. /*************************************************************************
  540.  *
  541.  -  IVTABC_CollapseRow
  542.  -
  543.  *  Stubbed out.  This table doesn't implement catagorization.
  544.  *
  545.  *
  546.  *
  547.  */
  548. STDMETHODIMP 
  549. IVTABC_CollapseRow(LPIVTABC lpIVTAbc, ULONG cbIKey, LPBYTE pbIKey,
  550.     ULONG ulFlags, ULONG FAR * lpulRowCount)
  551.  
  552. {
  553.     HRESULT hResult;
  554.  
  555.     /*
  556.      *  Validate parameters
  557.      */
  558.  
  559.     IVTABC_ValidateObject(CollapseRow, lpIVTAbc);
  560.  
  561.     Validate_IMAPITable_CollapseRow(lpIVTAbc, cbIKey, pbIKey, ulFlags, lpulRowCount);
  562.  
  563.  
  564.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  565.  
  566.     DebugTraceResult(IVTABC_CollapseRow, hResult);
  567.     return hResult;
  568.  
  569. }
  570.  
  571. /*************************************************************************
  572.  *
  573.  -  IVTABC_WaitForCompletion
  574.  -
  575.  *  Stubbed out.
  576.  *
  577.  *
  578.  *
  579.  */
  580. STDMETHODIMP 
  581. IVTABC_WaitForCompletion(LPIVTABC lpIVTAbc, ULONG ulFlags,
  582.     ULONG ulTimeout, ULONG FAR * lpulTableStatus)
  583. {
  584.     HRESULT hResult;
  585.  
  586.     IVTABC_ValidateObject(WaitForCompletion, lpIVTAbc);
  587.     
  588.     Validate_IMAPITable_WaitForCompletion(lpIVTAbc, ulFlags, ulTimeout, 
  589.                                             lpulTableStatus);
  590.  
  591.  
  592.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  593.  
  594.     DebugTraceResult(IVTABC_WaitForCompletion, hResult);
  595.     return hResult;
  596.  
  597. }
  598. /*************************************************************************
  599.  *
  600.  -  IVTABC_Abort
  601.  -
  602.  *  Nothing ever to abort...
  603.  *
  604.  *
  605.  *
  606.  */
  607. STDMETHODIMP 
  608. IVTABC_Abort(LPIVTABC lpIVTAbc)
  609.  
  610. {
  611.  
  612.     /*
  613.      *  Validate parameters
  614.      */
  615.  
  616.     IVTABC_ValidateObject(Abort, lpIVTAbc);
  617.  
  618.     Validate_IMAPITable_Abort(lpIVTAbc);
  619.  
  620.     return hrSuccess;
  621.  
  622. }
  623.  
  624. /*************************************************************************
  625.  *
  626.  *
  627.  -  IVTABC_Advise
  628.  -
  629.  *
  630.  *
  631.  *
  632.  */
  633. STDMETHODIMP 
  634. IVTABC_Advise(LPIVTABC lpIVTAbc,
  635.     ULONG ulEventmask,
  636.     LPMAPIADVISESINK lpAdviseSink,
  637.     ULONG FAR * lpulConnection)
  638. {
  639.     HRESULT hResult = hrSuccess;
  640.     UINT iAdvise;
  641.  
  642.     
  643.     /*
  644.      *  Validate the parameters
  645.      */
  646.     
  647.     IVTABC_ValidateObject(Advise, lpIVTAbc);
  648.     
  649.     Validate_IMAPITable_Advise(lpIVTAbc, ulEventmask, lpAdviseSink,
  650.                                 lpulConnection);
  651.     
  652.     /* Get the Critical Section */
  653.     EnterCriticalSection(&lpIVTAbc->cs);
  654.  
  655.     for (iAdvise = 0;
  656.         lpIVTAbc->parglpAdvise && iAdvise < lpIVTAbc->cAdvise;
  657.         ++iAdvise)
  658.     {
  659.         if (lpIVTAbc->parglpAdvise[iAdvise] == NULL)
  660.             break;
  661.     }
  662.  
  663.     if (iAdvise >= lpIVTAbc->cAdvise)
  664.     {
  665.         /*
  666.          *   Realloc the array if it exists
  667.          */
  668.         if (lpIVTAbc->parglpAdvise)
  669.         {
  670.             lpIVTAbc->parglpAdvise = lpIVTAbc->lpMalloc->lpVtbl->Realloc(
  671.                 lpIVTAbc->lpMalloc,
  672.                 lpIVTAbc->parglpAdvise,
  673.                 (lpIVTAbc->cAdvise + 1) * sizeof(LPMAPIADVISESINK));
  674.         }
  675.         else
  676.         {
  677.             lpIVTAbc->parglpAdvise = lpIVTAbc->lpMalloc->lpVtbl->Alloc(
  678.                 lpIVTAbc->lpMalloc,
  679.                 (lpIVTAbc->cAdvise + 1) * sizeof(LPMAPIADVISESINK));
  680.         }
  681.  
  682.         /*
  683.          *  Could we get the desired memory?
  684.          */
  685.         if (lpIVTAbc->parglpAdvise == NULL)
  686.         {
  687.             hResult = MakeResult(E_OUTOFMEMORY);
  688.             goto ret;
  689.         }
  690.     }
  691.  
  692.     lpIVTAbc->cAdvise++;
  693.  
  694.     *lpulConnection = lpIVTAbc->ulConnectMic + iAdvise;
  695.  
  696.     lpIVTAbc->parglpAdvise[iAdvise] = lpAdviseSink;
  697.  
  698.     lpAdviseSink->lpVtbl->AddRef(lpAdviseSink);
  699.  
  700. ret:
  701.     /* leave critical section */
  702.     LeaveCriticalSection(&lpIVTAbc->cs);
  703.  
  704.     DebugTraceResult(IVTABC_Advise, hResult);
  705.     return hResult;
  706. }
  707.  
  708. /*************************************************************************
  709.  *
  710.  *
  711.  -  IVTABC_Unadvise
  712.  -
  713.  *
  714.  *
  715.  *
  716.  */
  717. STDMETHODIMP 
  718. IVTABC_Unadvise(LPIVTABC lpIVTAbc, ULONG ulConnection)
  719. {
  720.     LPMAPIADVISESINK padvise;
  721.     UINT iAdvise;
  722.     HRESULT hResult = hrSuccess;
  723.  
  724.     IVTABC_ValidateObject(Unadvise, lpIVTAbc);
  725.  
  726.     Validate_IMAPITable_Unadvise(lpIVTAbc, ulConnection);
  727.  
  728.  
  729.     if (ulConnection - lpIVTAbc->ulConnectMic > (ULONG) lpIVTAbc->cAdvise)
  730.     {
  731.         DebugTraceSc(IVTABC_Unadvise, E_INVALIDARG);
  732.         return ResultFromScode(E_INVALIDARG);
  733.     }
  734.  
  735.     /* Get the Critical Section */
  736.     EnterCriticalSection(&lpIVTAbc->cs);
  737.  
  738.     iAdvise = (UINT) (ulConnection - lpIVTAbc->ulConnectMic);
  739.     padvise = lpIVTAbc->parglpAdvise[iAdvise];
  740.     padvise->lpVtbl->Release(padvise);
  741.     lpIVTAbc->parglpAdvise[iAdvise] = NULL;
  742.     lpIVTAbc->cAdvise--;
  743.  
  744.     /* leave critical section */
  745.     LeaveCriticalSection(&lpIVTAbc->cs);
  746.  
  747.     DebugTraceResult(IVTABC_Unadvise, hResult);
  748.     return hResult;
  749. }
  750.  
  751. /*************************************************************************
  752.  *
  753.  -  IVTABC_GetStatus
  754.  -
  755.  *  Returns the status of this table.  This table really isn't
  756.  *  dynamic yet, but it could be...
  757.  *
  758.  *
  759.  */
  760. STDMETHODIMP 
  761. IVTABC_GetStatus(LPIVTABC lpIVTAbc,
  762.     ULONG * lpulTableStatus,
  763.     ULONG * lpulTableType)
  764. {
  765.  
  766.     /*
  767.      *  Parameter checking
  768.      */
  769.  
  770.     IVTABC_ValidateObject(GetStatus, lpIVTAbc);
  771.  
  772.     Validate_IMAPITable_GetStatus(lpIVTAbc, lpulTableStatus, lpulTableType);
  773.  
  774.  
  775.     *lpulTableStatus = TBLSTAT_COMPLETE;
  776.     *lpulTableType = TBLTYPE_DYNAMIC;
  777.  
  778.     return hrSuccess;
  779. }
  780.  
  781. /*************************************************************************
  782.  *
  783.  -  IVTABC_SetColumns
  784.  -
  785.  *
  786.  *  SetColumns for contents table.
  787.  *
  788.  */
  789. STDMETHODIMP 
  790. IVTABC_SetColumns(LPIVTABC lpIVTAbc,
  791.     LPSPropTagArray lpPTAColSet,
  792.     ULONG ulFlags)
  793. {
  794.     SCODE scode;
  795.     HRESULT hResult = hrSuccess;
  796.     int cbSizeOfColSet;
  797.     LPSPropTagArray lpPTAColSetT;
  798.     ULONG uliCol;
  799.  
  800.     /*
  801.      *  Check parameters
  802.      */
  803.     IVTABC_ValidateObject(SetColumns, lpIVTAbc);
  804.     
  805.     Validate_IMAPITable_SetColumns(lpIVTAbc, lpPTAColSet, ulFlags);
  806.  
  807.  
  808.     /*
  809.      *  Verify that there are no PT_ERRORs here...
  810.      */
  811.     for (uliCol = 0; uliCol < lpPTAColSet->cValues; uliCol++)
  812.     {
  813.         if (PROP_TYPE(lpPTAColSet->aulPropTag[uliCol]) == PT_ERROR)
  814.         {
  815.             hResult = ResultFromScode(E_INVALIDARG);
  816.  
  817.             DebugTraceResult(IVTABC_GetStatus, hResult);
  818.             return hResult;
  819.         }
  820.     }
  821.  
  822.     /*
  823.      *  Allocate a new column set.
  824.      */
  825.  
  826.     cbSizeOfColSet = CbNewSPropTagArray(lpPTAColSet->cValues);
  827.  
  828.     scode = lpIVTAbc->lpAllocBuff(cbSizeOfColSet,(LPVOID *) &lpPTAColSetT);
  829.  
  830.     if (FAILED(scode))
  831.     {
  832.         hResult = ResultFromScode(scode);
  833.  
  834.         DebugTraceResult(IVTABC_GetStatus, hResult);
  835.         return hResult;
  836.     }
  837.  
  838.     /*
  839.      *  Copy the column set in
  840.      */
  841.     if (cbSizeOfColSet)
  842.         memcpy(lpPTAColSetT, lpPTAColSet, cbSizeOfColSet);
  843.  
  844.  
  845.     EnterCriticalSection(&lpIVTAbc->cs);
  846.  
  847.  
  848.     if (lpIVTAbc->lpPTAColSet != ptagaivtabcColSet)
  849.     {
  850.         /*
  851.          *  Free up the old column set
  852.          */
  853.         lpIVTAbc->lpFreeBuff(lpIVTAbc->lpPTAColSet);
  854.     }
  855.  
  856.     lpIVTAbc->lpPTAColSet = lpPTAColSetT;
  857.  
  858.  
  859.     LeaveCriticalSection(&lpIVTAbc->cs);
  860.     
  861.  
  862.     return hrSuccess;
  863.  
  864. }
  865.  
  866. /*************************************************************************
  867.  *
  868.  -  IVTABC_QueryColumns
  869.  -
  870.  *
  871.  *
  872.  *  I always have all my columns available...  and active.
  873.  */
  874. STDMETHODIMP 
  875. IVTABC_QueryColumns(LPIVTABC lpIVTAbc,
  876.     ULONG ulFlags,
  877.     LPSPropTagArray FAR * lppColumns)
  878. {
  879.     SCODE scode;
  880.     HRESULT hResult = hrSuccess;
  881.     int cbSizeOfColSet;
  882.  
  883.     /*
  884.      *  Check parameters
  885.      */
  886.  
  887.     IVTABC_ValidateObject(QueryColumns, lpIVTAbc);
  888.  
  889.     Validate_IMAPITable_QueryColumns(lpIVTAbc, ulFlags, lppColumns);
  890.  
  891.  
  892.     EnterCriticalSection(&lpIVTAbc->cs);
  893.  
  894.     /*
  895.      *  Allocate enough memory for the column set
  896.      */
  897.     if (ulFlags & TBL_ALL_COLUMNS)
  898.  
  899.         cbSizeOfColSet = sizeof(ULONG) +
  900.             (int)(ptagaivtabcColSet->cValues) * sizeof(ULONG);
  901.     else
  902.         cbSizeOfColSet = sizeof(ULONG) +
  903.             (int)lpIVTAbc->lpPTAColSet->cValues * sizeof(ULONG);
  904.  
  905.  
  906.     scode = lpIVTAbc->lpAllocBuff (cbSizeOfColSet,(LPVOID *) lppColumns);
  907.  
  908.     if (FAILED(scode))
  909.     {
  910.         hResult = ResultFromScode(scode);
  911.         goto out;
  912.     }
  913.  
  914.     /*
  915.      *  Copy the column set in
  916.      */
  917.     if (ulFlags & TBL_ALL_COLUMNS)
  918.         memcpy(*lppColumns, ptagaivtabcColSet, cbSizeOfColSet);
  919.     else
  920.         memcpy(*lppColumns, lpIVTAbc->lpPTAColSet, cbSizeOfColSet);
  921.  
  922.  
  923. out:
  924.     LeaveCriticalSection(&lpIVTAbc->cs);
  925.  
  926.     DebugTraceResult(IVTABC_QueryColumns, hResult);
  927.     return hResult;
  928.  
  929. }
  930.  
  931. /*************************************************************************
  932.  *
  933.  -  IVTABC_GetCollapseState
  934.  -
  935.  *  Stubbed out.  Only necessary if this table were to support categorization.
  936.  *
  937.  *
  938.  *
  939.  */
  940. STDMETHODIMP
  941. IVTABC_GetCollapseState(LPIVTABC lpIVTAbc,
  942.                         ULONG ulFlags,
  943.                         ULONG cbInstanceKey,
  944.                         LPBYTE pbInstanceKey,
  945.                         ULONG FAR * lpcbCollapseState,
  946.                         LPBYTE FAR * lppbCollapseState)
  947. {
  948.  
  949.     HRESULT hResult;
  950.  
  951.     /*
  952.      *  Check parameters
  953.      */
  954.  
  955.     IVTABC_ValidateObject(GetCollapseState, lpIVTAbc);
  956.  
  957.     Validate_IMAPITable_GetCollapseState(lpIVTAbc, ulFlags, cbInstanceKey,
  958.                                         pbInstanceKey, lpcbCollapseState,
  959.                                         lppbCollapseState);
  960.  
  961.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  962.     DebugTraceResult(IVTABC_GetCollapseState, hResult);
  963.     return hResult;
  964. }
  965.  
  966. /*************************************************************************
  967.  *
  968.  -  IVTABC_SetCollapseState
  969.  -
  970.  *  Stubbed out.  Only necessary if this table were to support categorization.
  971.  *
  972.  *
  973.  *
  974.  */
  975. STDMETHODIMP
  976. IVTABC_SetCollapseState(LPIVTABC lpIVTAbc,
  977.                         ULONG ulFlags,
  978.                         ULONG cbCollapseState,
  979.                         LPBYTE pbCollapseState,
  980.                         BOOKMARK FAR * lpbkLocation)
  981. {
  982.  
  983.     HRESULT hResult;
  984.  
  985.     /*
  986.      *  Check parameters
  987.      */
  988.  
  989.     IVTABC_ValidateObject(SetCollapseState, lpIVTAbc);
  990.  
  991.     Validate_IMAPITable_SetCollapseState(lpIVTAbc, ulFlags, cbCollapseState,
  992.                                         pbCollapseState, lpbkLocation);
  993.  
  994.  
  995.     hResult = ResultFromScode(MAPI_E_NO_SUPPORT);
  996.     DebugTraceResult(IVTABC_SetCollapseState, hResult);
  997.     return hResult;
  998. }
  999.