Leaked source code of windows server 2003
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.

109 lines
2.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: EnumAz.cpp
  7. //
  8. //
  9. // History: 8-13-2001 Hiteshr Created
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "headers.h"
  13. //DEBUG_DECLARE_INSTANCE_COUNTER(CAzCollection);
  14. template<class IAzCollection, class IAzInterface, class CObjectAz>
  15. CAzCollection<IAzCollection, IAzInterface, CObjectAz>
  16. ::CAzCollection(CComPtr<IAzCollection>& spAzCollection,
  17. CContainerAz* pParentContainerAz)
  18. :m_spAzCollection(spAzCollection),
  19. m_pParentContainerAz(pParentContainerAz)
  20. {
  21. TRACE_CONSTRUCTOR_EX(DEB_SNAPIN,CAzCollection);
  22. // DEBUG_INCREMENT_INSTANCE_COUNTER(CAzCollection);
  23. }
  24. template<class IAzCollection, class IAzInterface, class CObjectAz>
  25. CAzCollection<IAzCollection, IAzInterface, CObjectAz>
  26. ::~CAzCollection()
  27. {
  28. TRACE_DESTRUCTOR_EX(DEB_SNAPIN,CAzCollection);
  29. // DEBUG_DECREMENT_INSTANCE_COUNTER(CAzCollection##IAzCollection);
  30. }
  31. template<class IAzCollection, class IAzInterface, class CObjectAz>
  32. HRESULT
  33. CAzCollection<IAzCollection, IAzInterface, CObjectAz>
  34. ::Count(LONG* plCount)
  35. {
  36. TRACE_METHOD_EX(DEB_SNAPIN,CAzCollection,Count)
  37. if(!plCount)
  38. {
  39. ASSERT(plCount);
  40. return E_POINTER;
  41. }
  42. HRESULT hr = m_spAzCollection->get_Count(plCount);
  43. CHECK_HRESULT(hr);
  44. return hr;
  45. }
  46. //
  47. //
  48. template<class IAzCollection, class IAzInterface, class CObjectAz>
  49. CBaseAz*
  50. CAzCollection<IAzCollection, IAzInterface, CObjectAz>
  51. ::GetItem(UINT iIndex)
  52. {
  53. TRACE_METHOD_EX(DEB_SNAPIN,CAzCollection,Next);
  54. VARIANT var;
  55. VariantInit(&var);
  56. HRESULT hr = m_spAzCollection->get_Item(iIndex, &var);
  57. if(FAILED(hr))
  58. {
  59. //
  60. //*ppObjectAz is null and S_OK is returned when there are
  61. //no more items.
  62. //
  63. if(hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS))
  64. {
  65. return NULL;
  66. }
  67. else
  68. {
  69. DBG_OUT_HRESULT(hr);
  70. return NULL;
  71. }
  72. }
  73. ASSERT(VT_DISPATCH == var.vt);
  74. CComPtr<IDispatch> spDispatch = var.pdispVal;
  75. //VariantClear(&var);
  76. ((IDispatch*)(var.pdispVal))->Release();
  77. CComPtr<IAzInterface>spAzInterface;
  78. hr = spDispatch.QueryInterface(&spAzInterface);
  79. if(FAILED(hr))
  80. {
  81. DBG_OUT_HRESULT(hr);
  82. return NULL;
  83. }
  84. //
  85. //Create CObjectAz and return it.
  86. //
  87. CObjectAz *pObjectAz = new CObjectAz(spAzInterface, m_pParentContainerAz);
  88. if(!pObjectAz)
  89. {
  90. hr = E_OUTOFMEMORY;
  91. DBG_OUT_HRESULT(hr);
  92. return NULL;
  93. }
  94. return pObjectAz;
  95. }