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.

146 lines
2.4 KiB

  1. #include "dataobj.h"
  2. CEnumFormatEtc::CEnumFormatEtc(
  3. LPUNKNOWN pUnkRef,
  4. ULONG cFE,
  5. LPFORMATETC prgFE
  6. )
  7. {
  8. UINT i;
  9. m_cRef = 0;
  10. m_pUnkRef = pUnkRef;
  11. m_iCur = 0;
  12. m_cfe = cFE;
  13. m_prgfe = new FORMATETC[ (UINT) cFE ];
  14. if (NULL != m_prgfe)
  15. {
  16. for(i=0; i<cFE; i++)
  17. m_prgfe[i] = prgFE[i];
  18. }
  19. return;
  20. }
  21. CEnumFormatEtc::~CEnumFormatEtc(void)
  22. {
  23. if (NULL != m_prgfe)
  24. delete [] m_prgfe;
  25. return;
  26. }
  27. STDMETHODIMP
  28. CEnumFormatEtc::QueryInterface(
  29. REFIID riid,
  30. LPLPVOID ppv
  31. )
  32. {
  33. *ppv = NULL;
  34. if(IsEqualIID(riid, IID_IUnknown)
  35. || IsEqualIID(riid, IID_IEnumFORMATETC))
  36. {
  37. *ppv = (LPVOID) this;
  38. }
  39. if (NULL != *ppv)
  40. {
  41. ((LPUNKNOWN)*ppv)->AddRef();
  42. return NOERROR;
  43. }
  44. return ResultFromScode(E_NOINTERFACE);
  45. }
  46. STDMETHODIMP_(ULONG)
  47. CEnumFormatEtc::AddRef(void)
  48. {
  49. ++m_cRef;
  50. m_pUnkRef->AddRef();
  51. return m_cRef;
  52. }
  53. STDMETHODIMP_(ULONG)
  54. CEnumFormatEtc::Release(void)
  55. {
  56. ULONG cRefT;
  57. cRefT = --m_cRef;
  58. if (0 == m_cRef)
  59. delete this;
  60. return cRefT;
  61. }
  62. STDMETHODIMP
  63. CEnumFormatEtc::Next(
  64. ULONG cFE,
  65. LPFORMATETC pFE,
  66. ULONG FAR *pulFE
  67. )
  68. {
  69. ULONG cReturn = 0L;
  70. if (NULL == m_prgfe)
  71. return ResultFromScode(S_FALSE);
  72. if (NULL == pulFE)
  73. {
  74. if (1L != cFE)
  75. return ResultFromScode(E_POINTER);
  76. }
  77. else
  78. *pulFE = 0L;
  79. if (NULL == pFE || m_iCur >= m_cfe)
  80. return ResultFromScode(S_FALSE);
  81. while ( (m_iCur < m_cfe) && (cFE > 0) )
  82. {
  83. *pFE++ = m_prgfe[m_iCur++];
  84. ++cReturn;
  85. --cFE;
  86. }
  87. if (NULL != pulFE)
  88. *pulFE = cReturn;
  89. return NOERROR;
  90. }
  91. STDMETHODIMP
  92. CEnumFormatEtc::Skip(
  93. ULONG cSkip
  94. )
  95. {
  96. if ( ( (m_iCur+cSkip) > m_cfe) || (NULL == m_prgfe) )
  97. return ResultFromScode(S_FALSE);
  98. m_iCur += cSkip;
  99. return NOERROR;
  100. }
  101. STDMETHODIMP
  102. CEnumFormatEtc::Reset(void)
  103. {
  104. m_iCur = 0;
  105. return NOERROR;
  106. }
  107. STDMETHODIMP
  108. CEnumFormatEtc::Clone(
  109. LPENUMFORMATETC FAR *ppEnum
  110. )
  111. {
  112. PCEnumFormatEtc pNew;
  113. *ppEnum = NULL;
  114. pNew = new CEnumFormatEtc(m_pUnkRef, m_cfe, m_prgfe);
  115. if (NULL == pNew)
  116. return ResultFromScode(E_OUTOFMEMORY);
  117. pNew->AddRef();
  118. pNew->m_iCur = m_iCur;
  119. *ppEnum = pNew;
  120. return NOERROR;
  121. }
  122.