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.

93 lines
2.0 KiB

  1. // EnumTASK.cpp: implementation of the CEnumTASK class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "EnumTASK.h"
  5. //////////////////////////////////////////////////////////////////////
  6. // Construction/Destruction
  7. //////////////////////////////////////////////////////////////////////
  8. CEnumTASK::CEnumTASK(MMC_TASK *pTaskList, ULONG nTasks)
  9. : m_pTaskList(pTaskList), m_TaskCount(nTasks), m_CurrTask(0)
  10. {
  11. }
  12. CEnumTASK::~CEnumTASK()
  13. {
  14. if (m_pTaskList)
  15. delete [] m_pTaskList;
  16. }
  17. STDMETHODIMP CEnumTASK::QueryInterface(REFIID riid, LPVOID *ppv)
  18. {
  19. if (!ppv)
  20. return E_FAIL;
  21. *ppv = NULL;
  22. if (IsEqualIID(riid, IID_IUnknown))
  23. *ppv = static_cast<IEnumTASK *>(this);
  24. else if (IsEqualIID(riid, IID_IEnumTASK))
  25. *ppv = static_cast<IEnumTASK *>(this);
  26. if (*ppv)
  27. {
  28. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  29. return S_OK;
  30. }
  31. return E_NOINTERFACE;
  32. }
  33. STDMETHODIMP_(ULONG) CEnumTASK::AddRef()
  34. {
  35. return InterlockedIncrement((LONG *)&m_cref);
  36. }
  37. STDMETHODIMP_(ULONG) CEnumTASK::Release()
  38. {
  39. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  40. {
  41. delete this;
  42. return 0;
  43. }
  44. return m_cref;
  45. }
  46. HRESULT CEnumTASK::Next(
  47. /* [in] */ ULONG celt,
  48. /* [length_is][size_is][out] */ MMC_TASK __RPC_FAR *rgelt,
  49. /* [out] */ ULONG __RPC_FAR *pceltFetched)
  50. {
  51. *pceltFetched = 0;
  52. if (m_CurrTask < m_TaskCount) {
  53. if (rgelt != NULL) {
  54. CopyMemory(rgelt, &m_pTaskList[m_CurrTask++], sizeof(MMC_TASK));
  55. *pceltFetched = 1;
  56. }
  57. }
  58. return (*pceltFetched != 0) ? S_OK : S_FALSE;
  59. }
  60. HRESULT CEnumTASK::Skip(
  61. /* [in] */ ULONG celt)
  62. {
  63. return E_NOTIMPL;
  64. }
  65. HRESULT CEnumTASK::Reset( void)
  66. {
  67. m_CurrTask = 0;
  68. return S_OK;
  69. }
  70. HRESULT CEnumTASK::Clone(
  71. /* [out] */ IEnumTASK __RPC_FAR *__RPC_FAR *ppenum)
  72. {
  73. return E_NOTIMPL;
  74. }