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.

131 lines
2.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // dsenum.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class DSEnumerator.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/20/1998 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <ias.h>
  19. #include <iasutil.h>
  20. #include <dsenum.h>
  21. #include <dsobject.h>
  22. #include <new>
  23. DEFINE_TRACELIFE(DSEnumerator);
  24. STDMETHODIMP_(ULONG) DSEnumerator::AddRef()
  25. {
  26. return InterlockedIncrement(&refCount);
  27. }
  28. STDMETHODIMP_(ULONG) DSEnumerator::Release()
  29. {
  30. LONG l = InterlockedDecrement(&refCount);
  31. if (l == 0) { delete this; }
  32. return l;
  33. }
  34. STDMETHODIMP DSEnumerator::QueryInterface(const IID& iid, void** ppv)
  35. {
  36. if (iid == __uuidof(IUnknown))
  37. {
  38. *ppv = static_cast<IUnknown*>(this);
  39. }
  40. else if (iid == __uuidof(IEnumVARIANT))
  41. {
  42. *ppv = static_cast<IEnumVARIANT*>(this);
  43. }
  44. else
  45. {
  46. return E_NOINTERFACE;
  47. }
  48. InterlockedIncrement(&refCount);
  49. return S_OK;
  50. }
  51. STDMETHODIMP DSEnumerator::Next(ULONG celt,
  52. VARIANT* rgVar,
  53. ULONG* pCeltFetched)
  54. {
  55. HRESULT hr;
  56. try
  57. {
  58. if (pCeltFetched) { *pCeltFetched = 0; }
  59. // We have to use our own 'fetched' parameter, since we need the
  60. // number fetched even if the caller doesn't.
  61. ULONG fetched = 0;
  62. _com_util::CheckError(hr = subject->Next(celt, rgVar, &fetched));
  63. if (pCeltFetched) { *pCeltFetched = fetched; }
  64. //////////
  65. // Iterate through the returned objects ...
  66. //////////
  67. while (fetched--)
  68. {
  69. //////////
  70. // ... and convert them to DSObjects.
  71. //////////
  72. IDataStoreObject* obj = parent->spawn(V_DISPATCH(rgVar));
  73. V_DISPATCH(rgVar)->Release();
  74. V_DISPATCH(rgVar) = obj;
  75. ++rgVar;
  76. }
  77. }
  78. CATCH_AND_RETURN()
  79. return hr;
  80. }
  81. STDMETHODIMP DSEnumerator::Skip(ULONG celt)
  82. {
  83. return subject->Skip(celt);
  84. }
  85. STDMETHODIMP DSEnumerator::Reset()
  86. {
  87. return subject->Reset();
  88. }
  89. STDMETHODIMP DSEnumerator::Clone(IEnumVARIANT** ppEnum)
  90. {
  91. if (ppEnum == NULL) { return E_INVALIDARG; }
  92. *ppEnum = NULL;
  93. try
  94. {
  95. // Get the real enumerator.
  96. CComPtr<IEnumVARIANT> newSubject;
  97. _com_util::CheckError(subject->Clone(&newSubject));
  98. // Construct our wrapper.
  99. (*ppEnum = new DSEnumerator(parent, newSubject))->AddRef();
  100. }
  101. CATCH_AND_RETURN()
  102. return S_OK;
  103. }