pubenum.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 3k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation 
  4. //
  5. // File: pubenum.cpp
  6. //
  7. // The current order of enumeration is Legacy --> Darwin --> SMS
  8. //
  9. // History:
  10. //         1-18-97  by dli
  11. //------------------------------------------------------------------------
  12. #include "priv.h"
  13. // Do not build this file if on Win9X or NT4
  14. #ifndef DOWNLEVEL_PLATFORM
  15. #include "pubenum.h"
  16. void _DestroyHdpaEnum(HDPA hdpaEnum)
  17. {
  18.     ASSERT(IsValidHDPA(hdpaEnum));
  19.     IEnumPublishedApps * pepa;
  20.     int idpa;
  21.     for (idpa = 0; idpa < DPA_GetPtrCount(hdpaEnum); idpa++)
  22.     {
  23.         pepa = (IEnumPublishedApps *)DPA_GetPtr(hdpaEnum, idpa);
  24.         if (EVAL(pepa))
  25.             pepa->Release();
  26.     }
  27.     DPA_Destroy(hdpaEnum);
  28. }
  29. CShellEnumPublishedApps::CShellEnumPublishedApps(HDPA hdpaEnum) : _cRef(1), _hdpaEnum(hdpaEnum)
  30. {
  31. }
  32. CShellEnumPublishedApps::~CShellEnumPublishedApps()
  33. {
  34.     if (_hdpaEnum)
  35.         _DestroyHdpaEnum(_hdpaEnum);
  36. }
  37. // IEnumPublishedApps::QueryInterface
  38. HRESULT CShellEnumPublishedApps::QueryInterface(REFIID riid, LPVOID * ppvOut)
  39.     static const QITAB qit[] = {
  40.         QITABENT(CShellEnumPublishedApps, IEnumPublishedApps),                  // IID_IEnumPublishedApps
  41.         { 0 },
  42.     };
  43.     return QISearch(this, qit, riid, ppvOut);
  44. }
  45. // IEnumPublishedApps::AddRef
  46. ULONG CShellEnumPublishedApps::AddRef()
  47. {
  48.     _cRef++;
  49.     TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::AddRef called, new _cRef=%lX", _cRef);
  50.     return _cRef;
  51. }
  52. // IEnumPublishedApps::Release
  53. ULONG CShellEnumPublishedApps::Release()
  54. {
  55.     _cRef--;
  56.     TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::Release called, new _cRef=%lX", _cRef);
  57.     if (_cRef > 0)
  58.         return _cRef;
  59.     delete this;
  60.     return 0;
  61. }
  62. // IEnumPublishedApps::Next
  63. HRESULT CShellEnumPublishedApps::Next(IPublishedApp ** ppia)
  64. {
  65.     HRESULT hres = E_FAIL;
  66.     if (_hdpaEnum)
  67.     {
  68.         IEnumPublishedApps * pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  69.         // If pepa is not valid or pepa->Next failed, we skip this Enumerator, and go on to the next
  70.         // one until we hit the limit
  71.         
  72.         while ((!pepa || FAILED(hres = pepa->Next(ppia)))  && (_iEnum < DPA_GetPtrCount(_hdpaEnum)))
  73.         {
  74.             _iEnum++;
  75.             pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  76.         }
  77.     }    
  78.     return hres;
  79. }
  80. // IEnumPublishedApps::Reset
  81. HRESULT CShellEnumPublishedApps::Reset(void)
  82. {
  83.     // Call reset on everyone in the list and set our index iEnum to 0;
  84.     if (_hdpaEnum)
  85.     {
  86.         IEnumPublishedApps * pepa;
  87.         int idpa;
  88.         for (idpa = 0; idpa < DPA_GetPtrCount(_hdpaEnum); idpa++)
  89.         {
  90.             pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, idpa);
  91.             if (pepa)
  92.                 pepa->Reset();
  93.         }
  94.         _iEnum = 0;
  95.         return S_OK;
  96.     }
  97.     
  98.     return E_FAIL;
  99. }
  100. #endif //DOWNLEVEL_PLATFORM