Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.9 KiB

  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. {
  40. static const QITAB qit[] = {
  41. QITABENT(CShellEnumPublishedApps, IEnumPublishedApps), // IID_IEnumPublishedApps
  42. { 0 },
  43. };
  44. return QISearch(this, qit, riid, ppvOut);
  45. }
  46. // IEnumPublishedApps::AddRef
  47. ULONG CShellEnumPublishedApps::AddRef()
  48. {
  49. _cRef++;
  50. TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::AddRef called, new _cRef=%lX", _cRef);
  51. return _cRef;
  52. }
  53. // IEnumPublishedApps::Release
  54. ULONG CShellEnumPublishedApps::Release()
  55. {
  56. _cRef--;
  57. TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::Release called, new _cRef=%lX", _cRef);
  58. if (_cRef > 0)
  59. return _cRef;
  60. delete this;
  61. return 0;
  62. }
  63. // IEnumPublishedApps::Next
  64. HRESULT CShellEnumPublishedApps::Next(IPublishedApp ** ppia)
  65. {
  66. HRESULT hres = E_FAIL;
  67. if (_hdpaEnum)
  68. {
  69. IEnumPublishedApps * pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  70. //
  71. // If pepa is not valid or pepa->Next failed, or at the end of the current enumerator,
  72. // we skip this Enumerator, and go on to the next one until we hit the limit
  73. while ((!pepa || S_OK != (hres = pepa->Next(ppia))) && (_iEnum < DPA_GetPtrCount(_hdpaEnum)))
  74. {
  75. _iEnum++;
  76. pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  77. }
  78. }
  79. return hres;
  80. }
  81. // IEnumPublishedApps::Reset
  82. HRESULT CShellEnumPublishedApps::Reset(void)
  83. {
  84. // Call reset on everyone in the list and set our index iEnum to 0;
  85. if (_hdpaEnum)
  86. {
  87. IEnumPublishedApps * pepa;
  88. int idpa;
  89. for (idpa = 0; idpa < DPA_GetPtrCount(_hdpaEnum); idpa++)
  90. {
  91. pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, idpa);
  92. if (pepa)
  93. pepa->Reset();
  94. }
  95. _iEnum = 0;
  96. return S_OK;
  97. }
  98. return E_FAIL;
  99. }
  100. #endif //DOWNLEVEL_PLATFORM