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.

336 lines
8.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Function: CEnumFmtEtc
  4. //
  5. // Synopsis: Implements the IEnumFormatEtc.
  6. // Used by the urlmon by dataobject and CreateEnumFormatEtc
  7. //
  8. // Arguments: (none)
  9. //
  10. // Returns:
  11. //
  12. // History: 12-22-95 JohannP (Johann Posch) Created
  13. //
  14. // Notes:
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <mon.h>
  18. PerfDbgTag(tagCEnumFmtEtc, "Urlmon", "Log CEnumFmtEtc", DEB_FORMAT);
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Method: CEnumFmtEtc::Create
  22. //
  23. // Synopsis:
  24. //
  25. // Arguments: [cfmtetc] --
  26. // [rgfmtetc] --
  27. //
  28. // Returns:
  29. //
  30. // History: 12-22-95 JohannP (Johann Posch) Created
  31. //
  32. // Notes:
  33. //
  34. //----------------------------------------------------------------------------
  35. CEnumFmtEtc * CEnumFmtEtc::Create(UINT cfmtetc, FORMATETC* rgfmtetc)
  36. {
  37. PerfDbgLog(tagCEnumFmtEtc, NULL, "+CEnumFmtEtc::Create");
  38. CEnumFmtEtc * pCEnumFEtc = NULL;
  39. if (cfmtetc >= 1)
  40. {
  41. // only create an enumerator if at least one element
  42. pCEnumFEtc = new CEnumFmtEtc();
  43. if (pCEnumFEtc)
  44. {
  45. if (pCEnumFEtc->Initialize(cfmtetc, rgfmtetc, 0) == FALSE)
  46. {
  47. delete pCEnumFEtc;
  48. pCEnumFEtc = NULL;
  49. }
  50. }
  51. }
  52. PerfDbgLog1(tagCEnumFmtEtc, NULL, "-CEnumFmtEtc::Create pEnum->(%lx)", pCEnumFEtc);
  53. return pCEnumFEtc;
  54. }
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Method: CEnumFmtEtc::Initialize
  58. //
  59. // Synopsis: set the size and position
  60. //
  61. // Arguments: [cfmtetc] -- number of elements
  62. // [iPos] -- position of enumerator
  63. //
  64. // Returns: true on success
  65. //
  66. // History: 12-22-95 JohannP (Johann Posch) Created
  67. //
  68. // Notes:
  69. //
  70. //----------------------------------------------------------------------------
  71. BOOL CEnumFmtEtc::Initialize(UINT cfmtetc, FORMATETC* rgfmtetc, UINT iPos)
  72. {
  73. LONG cbSize = sizeof(FORMATETC) * cfmtetc;
  74. _iNext = iPos;
  75. _cElements = cfmtetc;
  76. _pFmtEtc = (FORMATETC *) new FORMATETC [cfmtetc];
  77. if (_pFmtEtc)
  78. {
  79. memcpy(_pFmtEtc, rgfmtetc, cbSize);
  80. _cElements = cfmtetc;
  81. }
  82. else
  83. {
  84. _cElements = 0;
  85. }
  86. return _cElements != 0;
  87. }
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Method: CEnumFmtEtc::QueryInterface
  91. //
  92. // Synopsis:
  93. //
  94. // Arguments: [riid] --
  95. // [ppvObj] --
  96. //
  97. // Returns:
  98. //
  99. // History: 12-22-95 JohannP (Johann Posch) Created
  100. //
  101. // Notes:
  102. //
  103. //----------------------------------------------------------------------------
  104. STDMETHODIMP CEnumFmtEtc::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  105. {
  106. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::QueryInterface");
  107. HRESULT hr = NOERROR;
  108. if ( (riid == IID_IUnknown)
  109. || (riid == IID_IEnumFORMATETC))
  110. {
  111. *ppvObj = this;
  112. AddRef();
  113. }
  114. else
  115. {
  116. *ppvObj = NULL;
  117. hr = E_NOINTERFACE;
  118. }
  119. PerfDbgLog(tagCEnumFmtEtc, this, "-CEnumFmtEtc::QueryInterface");
  120. return hr;
  121. }
  122. //+---------------------------------------------------------------------------
  123. //
  124. // Function: CEnumFmtEtc::AddRef
  125. //
  126. // Synopsis:
  127. //
  128. // Arguments: [ULONG] --
  129. //
  130. // Returns:
  131. //
  132. // History: 12-22-95 JohannP (Johann Posch) Created
  133. //
  134. // Notes:
  135. //
  136. //----------------------------------------------------------------------------
  137. STDMETHODIMP_(ULONG) CEnumFmtEtc::AddRef(void)
  138. {
  139. GEN_VDATEPTRIN(this,ULONG,0L);
  140. LONG lRet = ++_CRefs;
  141. PerfDbgLog1(tagCEnumFmtEtc, this, "CEnumFmtEtc::AddRef(%ld)", lRet);
  142. return lRet;
  143. }
  144. //+---------------------------------------------------------------------------
  145. //
  146. // Function: CEnumFmtEtc::Release
  147. //
  148. // Synopsis:
  149. //
  150. // Arguments: [ULONG] --
  151. //
  152. // Returns:
  153. //
  154. // History: 12-22-95 JohannP (Johann Posch) Created
  155. //
  156. // Notes:
  157. //
  158. //----------------------------------------------------------------------------
  159. STDMETHODIMP_(ULONG) CEnumFmtEtc::Release(void)
  160. {
  161. GEN_VDATEPTRIN(this,ULONG,0L);
  162. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::Release");
  163. LONG lRet = --_CRefs;
  164. if (_CRefs == 0)
  165. {
  166. delete this;
  167. }
  168. PerfDbgLog1(tagCEnumFmtEtc, this, "-CEnumFmtEtc::Release(%ld)", lRet);
  169. return lRet;
  170. }
  171. //+---------------------------------------------------------------------------
  172. //
  173. // Method: CEnumFmtEtc::Next
  174. //
  175. // Synopsis:
  176. //
  177. // Arguments: [celt] --
  178. // [rgelt] --
  179. // [pceltFetched] --
  180. //
  181. // Returns:
  182. //
  183. // History: 12-22-95 JohannP (Johann Posch) Created
  184. //
  185. // Notes:
  186. //
  187. //----------------------------------------------------------------------------
  188. STDMETHODIMP CEnumFmtEtc::Next(ULONG celt, FORMATETC * rgelt, ULONG * pceltFetched)
  189. {
  190. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::Next");
  191. HRESULT hr;
  192. if (!rgelt)
  193. {
  194. hr = E_INVALIDARG;
  195. }
  196. else
  197. {
  198. for (ULONG i = 0; (i < celt) && (_iNext < _cElements); i++)
  199. {
  200. rgelt[i] = *(_pFmtEtc + _iNext++);
  201. }
  202. if (pceltFetched)
  203. {
  204. *pceltFetched = i;
  205. }
  206. hr = ((i == celt) ? NOERROR : S_FALSE);
  207. }
  208. PerfDbgLog1(tagCEnumFmtEtc, this, "-CEnumFmtEtc::Next (hr:%lx)", hr);
  209. return hr;
  210. }
  211. //+---------------------------------------------------------------------------
  212. //
  213. // Method: CEnumFmtEtc::Skip
  214. //
  215. // Synopsis:
  216. //
  217. // Arguments: [celt] --
  218. //
  219. // Returns:
  220. //
  221. // History: 12-22-95 JohannP (Johann Posch) Created
  222. //
  223. // Notes:
  224. //
  225. //----------------------------------------------------------------------------
  226. STDMETHODIMP CEnumFmtEtc::Skip(ULONG celt)
  227. {
  228. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::Skip");
  229. HRESULT hr;
  230. _iNext += celt;
  231. if (_iNext <= _cElements)
  232. {
  233. hr = NOERROR;
  234. }
  235. else
  236. {
  237. _iNext = _cElements;
  238. hr = S_FALSE;
  239. }
  240. PerfDbgLog1(tagCEnumFmtEtc, this, "-CEnumFmtEtc::Skip (hr:%lx)", hr);
  241. return hr;
  242. }
  243. //+---------------------------------------------------------------------------
  244. //
  245. // Method: CEnumFmtEtc::Reset
  246. //
  247. // Synopsis:
  248. //
  249. // Arguments: [void] --
  250. //
  251. // Returns:
  252. //
  253. // History: 12-22-95 JohannP (Johann Posch) Created
  254. //
  255. // Notes:
  256. //
  257. //----------------------------------------------------------------------------
  258. STDMETHODIMP CEnumFmtEtc::Reset(void)
  259. {
  260. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::Reset");
  261. _iNext = 0;
  262. PerfDbgLog1(tagCEnumFmtEtc, this, "-CEnumFmtEtc::Reset (hr:%lx)", S_OK);
  263. return S_OK;
  264. }
  265. //+---------------------------------------------------------------------------
  266. //
  267. // Method: CEnumFmtEtc::Clone
  268. //
  269. // Synopsis:
  270. //
  271. // Arguments: [ppenum] --
  272. //
  273. // Returns:
  274. //
  275. // History: 12-22-95 JohannP (Johann Posch) Created
  276. //
  277. // Notes:
  278. //
  279. //----------------------------------------------------------------------------
  280. STDMETHODIMP CEnumFmtEtc::Clone(IEnumFORMATETC ** ppenum)
  281. {
  282. PerfDbgLog(tagCEnumFmtEtc, this, "+CEnumFmtEtc::Clone");
  283. HRESULT hr;
  284. if (ppenum)
  285. {
  286. CEnumFmtEtc * pCEnumFEtc;
  287. TransAssert((_cElements > 0));
  288. pCEnumFEtc = new CEnumFmtEtc();
  289. if (pCEnumFEtc)
  290. {
  291. if (pCEnumFEtc->Initialize(_cElements, _pFmtEtc, _iNext) == FALSE)
  292. {
  293. delete pCEnumFEtc;
  294. pCEnumFEtc = NULL;
  295. }
  296. else
  297. {
  298. *ppenum = pCEnumFEtc;
  299. }
  300. }
  301. hr = ((*ppenum != NULL) ? NOERROR : E_OUTOFMEMORY);
  302. }
  303. else
  304. {
  305. hr = E_INVALIDARG;
  306. }
  307. PerfDbgLog1(tagCEnumFmtEtc, this, "-CEnumFmtEtc::Clone (hr:%lx)", hr);
  308. return hr;
  309. }