home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / vcoledb / provider / myprov / myproviderrs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  2.7 KB  |  98 lines

  1. // Implementation of the CMyProviderRowset
  2. //
  3. // This is a part of the ActiveX Template Library.
  4. // Copyright (C) 1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // ActiveX Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // ActiveX Template Library product.
  12.  
  13. #include "stdafx.h"
  14. #include "MyProviderRS.h"
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMyCommand::Execute
  18. HRESULT WINAPI CMyProviderCommand::Execute(IUnknown * pUnkOuter, REFIID riid, DBPARAMS * pParams,
  19.                                            LONG * pcRowsAffected, IUnknown ** ppRowset)
  20. {
  21.     CAgentRowset* pAgentRS;
  22.     return CreateRowset(pUnkOuter, riid, pParams, pcRowsAffected, ppRowset, pAgentRS);
  23. }
  24.  
  25.  
  26. template <class TInterface>
  27. ATLCOLUMNINFO* CommonGetColInfo(IUnknown* pPropsUnk, ULONG* pcCols)
  28. {
  29.     static ATLCOLUMNINFO _rgColumns[5];
  30.     ULONG ulCols = 0;
  31.  
  32.     CComQIPtr<TInterface> spProps = pPropsUnk;
  33.  
  34.     CDBPropIDSet set(DBPROPSET_ROWSET);
  35.     set.AddPropertyID(DBPROP_BOOKMARKS);
  36.     DBPROPSET* pPropSet = NULL;
  37.     ULONG ulPropSet = 0;
  38.     HRESULT hr;
  39.  
  40.     if (spProps)
  41.         hr = spProps->GetProperties(1, &set, &ulPropSet, &pPropSet);
  42.  
  43.     // Check the property flag for bookmarks, if it is set, set the zero ordinal
  44.     // entry in the column map with the bookmark information.
  45.  
  46.     if (pPropSet)
  47.     {
  48.         CComVariant var = pPropSet->rgProperties[0].vValue;
  49.         CoTaskMemFree(pPropSet->rgProperties);
  50.         CoTaskMemFree(pPropSet);
  51.  
  52.         if ((SUCCEEDED(hr) && (var.boolVal == VARIANT_TRUE)))
  53.         {
  54.             ADD_COLUMN_ENTRY_EX(ulCols, OLESTR("Bookmark"), 0, sizeof(DWORD), DBTYPE_BYTES,
  55.                 0, 0, GUID_NULL, CAgentMan, dwBookmark, DBCOLUMNFLAGS_ISBOOKMARK)
  56.             ulCols++;
  57.         }
  58.  
  59.     }
  60.  
  61.  
  62.     // Next set the other columns up.
  63.     ADD_COLUMN_ENTRY(ulCols, OLESTR("Command"), 1, 256, DBTYPE_STR, 0xFF, 0xFF,
  64.         GUID_NULL, CAgentMan, szCommand)
  65.     ulCols++;
  66.     ADD_COLUMN_ENTRY(ulCols, OLESTR("Text"), 2, 256, DBTYPE_STR, 0xFF, 0xFF,
  67.         GUID_NULL, CAgentMan, szText)
  68.     ulCols++;
  69.  
  70.     ADD_COLUMN_ENTRY(ulCols, OLESTR("Command2"), 3, 256, DBTYPE_STR, 0xFF, 0xFF,
  71.         GUID_NULL, CAgentMan, szCommand2)
  72.     ulCols++;
  73.     ADD_COLUMN_ENTRY(ulCols, OLESTR("Text2"), 4, 256, DBTYPE_STR, 0xFF, 0xFF,
  74.         GUID_NULL, CAgentMan, szText2)
  75.     ulCols++;
  76.  
  77.  
  78.     if (pcCols != NULL)
  79.         *pcCols = ulCols;
  80.  
  81.     return _rgColumns;
  82. }
  83.  
  84.  
  85.  
  86. ATLCOLUMNINFO* CAgentMan::GetColumnInfo(CMyProviderCommand* pThis, ULONG* pcCols)
  87. {
  88.     return CommonGetColInfo<ICommandProperties>(pThis->GetUnknown(), pcCols);
  89. }
  90.  
  91.  
  92. ATLCOLUMNINFO* CAgentMan::GetColumnInfo(CAgentRowset* pThis, ULONG* pcCols)
  93. {
  94.  
  95.     return CommonGetColInfo<IRowsetInfo>(pThis->GetUnknown(), pcCols);
  96.  
  97. }
  98.