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.

211 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: objfmts.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "objfmts.h"
  12. //____________________________________________________________________________
  13. //
  14. // Members: IEnumFORMATETC methods
  15. //____________________________________________________________________________
  16. STDMETHODIMP
  17. CObjFormats::Next(
  18. ULONG celt,
  19. FORMATETC *rgelt,
  20. ULONG *pceltFethed)
  21. {
  22. UINT cfetch = 0;
  23. HRESULT hr = S_FALSE; // assume less numbers
  24. if (m_iFmt < m_cFmt)
  25. {
  26. cfetch = m_cFmt - m_iFmt;
  27. if (cfetch >= celt)
  28. {
  29. cfetch = celt;
  30. hr = S_OK;
  31. }
  32. CopyMemory(rgelt, &m_aFmt[m_iFmt], cfetch * sizeof(FORMATETC));
  33. m_iFmt += cfetch;
  34. }
  35. if (pceltFethed)
  36. {
  37. *pceltFethed = cfetch;
  38. }
  39. return hr;
  40. }
  41. STDMETHODIMP
  42. CObjFormats::Skip(
  43. ULONG celt)
  44. {
  45. m_iFmt += celt;
  46. if (m_iFmt > m_cFmt)
  47. {
  48. m_iFmt = m_cFmt;
  49. return S_FALSE;
  50. }
  51. return S_OK;
  52. }
  53. STDMETHODIMP
  54. CObjFormats::Reset()
  55. {
  56. m_iFmt = 0;
  57. return S_OK;
  58. }
  59. STDMETHODIMP
  60. CObjFormats::Clone(
  61. IEnumFORMATETC ** ppenum)
  62. {
  63. return E_NOTIMPL;
  64. }
  65. //____________________________________________________________________________
  66. //
  67. // Function: Function to obtain the IEnumFORMATETC interface.
  68. //____________________________________________________________________________
  69. HRESULT
  70. GetObjFormats(
  71. UINT cfmt,
  72. FORMATETC * afmt,
  73. LPVOID * ppvObj)
  74. {
  75. ASSERT(ppvObj != NULL);
  76. ASSERT(afmt != NULL);
  77. FORMATETC * pFmt = new FORMATETC[cfmt];
  78. if (pFmt == NULL)
  79. return E_OUTOFMEMORY;
  80. CopyMemory(pFmt, afmt, cfmt * sizeof(FORMATETC));
  81. CComObject<CObjFormats>* pObjFormats;
  82. CComObject<CObjFormats>::CreateInstance(&pObjFormats);
  83. if (pObjFormats == NULL)
  84. {
  85. delete [] pFmt;
  86. return E_OUTOFMEMORY;
  87. }
  88. pObjFormats->Init(cfmt, pFmt);
  89. return pObjFormats->QueryInterface(IID_IEnumFORMATETC,
  90. reinterpret_cast<void**>(ppvObj));
  91. }
  92. //////////....................................................//////////////
  93. //////////....................................................//////////////
  94. //////////....................................................//////////////
  95. //////////....................................................//////////////
  96. //////////....................................................//////////////
  97. //////////....................................................//////////////
  98. //////////....................................................//////////////
  99. //////////....................................................//////////////
  100. //____________________________________________________________________________
  101. //
  102. // Members: CObjFormatsEx::IEnumFORMATETC methods
  103. //____________________________________________________________________________
  104. STDMETHODIMP
  105. CObjFormatsEx::Next(
  106. ULONG celt,
  107. FORMATETC *rgelt,
  108. ULONG *pceltFethed)
  109. {
  110. if (m_iCur == 1)
  111. return m_rgspEnums[1]->Next(celt, rgelt, pceltFethed);
  112. ULONG celtFethed1 = 0;
  113. HRESULT hr = m_rgspEnums[0]->Next(celt, rgelt, &celtFethed1);
  114. if (hr == S_OK)
  115. return S_OK;
  116. ULONG celt2 = celt - celtFethed1;
  117. ULONG celtFethed2 = 0;
  118. m_iCur = 1;
  119. hr = m_rgspEnums[1]->Next(celt2, &rgelt[celtFethed1], &celtFethed2);
  120. if (pceltFethed)
  121. *pceltFethed = celtFethed1 + celtFethed2;
  122. return hr;
  123. }
  124. STDMETHODIMP
  125. CObjFormatsEx::Skip(
  126. ULONG celt)
  127. {
  128. return E_NOTIMPL;
  129. }
  130. STDMETHODIMP
  131. CObjFormatsEx::Reset()
  132. {
  133. m_iCur = 0;
  134. m_rgspEnums[0]->Reset();
  135. m_rgspEnums[1]->Reset();
  136. return S_OK;
  137. }
  138. STDMETHODIMP
  139. CObjFormatsEx::Clone(
  140. IEnumFORMATETC ** ppenum)
  141. {
  142. return E_NOTIMPL;
  143. }
  144. HRESULT
  145. GetObjFormatsEx(
  146. IEnumFORMATETC* pEnum1,
  147. IEnumFORMATETC* pEnum2,
  148. IEnumFORMATETC** ppEnumOut)
  149. {
  150. ASSERT(pEnum1 != NULL);
  151. ASSERT(pEnum2 != NULL);
  152. ASSERT(ppEnumOut != NULL);
  153. if (!pEnum1 || !pEnum2 || !ppEnumOut)
  154. return E_INVALIDARG;
  155. CComObject<CObjFormatsEx>* pObj;
  156. CComObject<CObjFormatsEx>::CreateInstance(&pObj);
  157. if (pObj == NULL)
  158. return E_OUTOFMEMORY;
  159. pObj->Init(pEnum1, pEnum2);
  160. return pObj->QueryInterface(IID_IEnumFORMATETC,
  161. reinterpret_cast<void**>(ppEnumOut));
  162. }