ABCTBL3.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:22k
源码类别:

Windows编程

开发平台:

Visual C++

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