Source code of Windows XP (NT5)
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.

240 lines
6.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: simpenm.cxx
  7. //
  8. // Contents: SimpEnumSTATSTG class implementation
  9. //
  10. // Classes: CSimpEnumSTATSTG
  11. //
  12. // Functions:
  13. //
  14. // History: 04-May-96 HenryLee Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "simphead.cxx"
  18. #pragma hdrstop
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CSimpEnumSTATSTG::QueryInterface, public
  22. //
  23. // Synopsis: Init function
  24. //
  25. // Arguments: [riid] -- reference to desired interface ID
  26. // [ppvObj] -- output pointer to interface
  27. //
  28. // Returns: Appropriate status code
  29. //
  30. // History: 04-May-96 HenryLee Created
  31. //
  32. //----------------------------------------------------------------------------
  33. STDMETHODIMP CSimpEnumSTATSTG::QueryInterface (REFIID riid, void **ppvObj)
  34. {
  35. simpDebugOut((DEB_ITRACE,"In CSimpEnumSTATSTG::QueryInterface %p\n",this));
  36. SCODE sc = S_OK;
  37. if (ppvObj == NULL)
  38. return STG_E_INVALIDPOINTER;
  39. *ppvObj = NULL;
  40. if (riid == IID_IEnumSTATSTG || riid == IID_IUnknown)
  41. {
  42. *ppvObj = this;
  43. AddRef ();
  44. }
  45. else
  46. sc = E_NOINTERFACE;
  47. simpDebugOut((DEB_ITRACE, "Out CSimpEnumSTATSTG::QueryInterface\n"));
  48. return sc;
  49. }
  50. //+--------------------------------------------------------------
  51. //
  52. // Member: CSimpEnumSTATSTG::AddRef, public
  53. //
  54. // Synopsis:
  55. //
  56. // Returns: Appropriate status code
  57. //
  58. // History: 04-May-96 HenryLee Created
  59. //
  60. //---------------------------------------------------------------
  61. STDMETHODIMP_(ULONG) CSimpEnumSTATSTG::AddRef ()
  62. {
  63. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::AddRef()\n"));
  64. simpAssert(_cReferences > 0);
  65. LONG lRet = AtomicInc(&_cReferences);
  66. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::AddRef()\n"));
  67. return (ULONG) lRet;
  68. }
  69. //+--------------------------------------------------------------
  70. //
  71. // Member: CSimpEnumSTATSTG::Release, public
  72. //
  73. // Synopsis:
  74. //
  75. // Returns: Appropriate status code
  76. //
  77. // History: 04-May-96 HenryLee Created
  78. //
  79. //---------------------------------------------------------------
  80. STDMETHODIMP_(ULONG) CSimpEnumSTATSTG::Release ()
  81. {
  82. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::Release()\n"));
  83. simpAssert(_cReferences > 0);
  84. LONG lRet = AtomicDec(&_cReferences);
  85. if (lRet == 0)
  86. {
  87. delete this;
  88. }
  89. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::Release()\n"));
  90. return (ULONG) lRet;
  91. }
  92. //+--------------------------------------------------------------
  93. //
  94. // Member: CSimpEnumSTATSTG::Next, public
  95. //
  96. // Synopsis:
  97. //
  98. // Returns: Appropriate status code
  99. //
  100. // History: 04-May-96 HenryLee Created
  101. //
  102. //---------------------------------------------------------------
  103. STDMETHODIMP CSimpEnumSTATSTG::Next (ULONG celt, STATSTG *rgelt,
  104. ULONG *pceltFetched)
  105. {
  106. SCODE sc = S_OK;
  107. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::Next()\n"));
  108. if (celt != 1 || rgelt == NULL)
  109. return STG_E_INVALIDPARAMETER;
  110. if (pceltFetched)
  111. *pceltFetched = 0;
  112. if (_pdflCurrent == _pdfl && _pdfl != NULL)
  113. _pdflCurrent = _pdflCurrent->GetNext(); // skip the root directory
  114. if (_pdflCurrent != NULL)
  115. {
  116. memset (rgelt, 0, sizeof(STATSTG));
  117. rgelt->pwcsName = (WCHAR *) CoTaskMemAlloc (
  118. _pdflCurrent->GetName()->GetLength()+sizeof(WCHAR));
  119. if (rgelt->pwcsName)
  120. {
  121. memcpy (rgelt->pwcsName, _pdflCurrent->GetName()->GetBuffer(),
  122. _pdflCurrent->GetName()->GetLength());
  123. rgelt->pwcsName[_pdflCurrent->GetName()->GetLength()/
  124. sizeof(WCHAR)] = L'\0';
  125. rgelt->cbSize.LowPart = _pdflCurrent->GetSize();
  126. rgelt->cbSize.HighPart = 0;
  127. rgelt->type = STGTY_STREAM;
  128. _pdflCurrent = _pdflCurrent->GetNext();
  129. if (pceltFetched)
  130. *pceltFetched = 1;
  131. }
  132. else
  133. sc = STG_E_INSUFFICIENTMEMORY;
  134. }
  135. else // end of list
  136. {
  137. sc = S_FALSE;
  138. }
  139. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::Next()\n"));
  140. return sc;
  141. }
  142. //+--------------------------------------------------------------
  143. //
  144. // Member: CSimpEnumSTATSTG::Skip, public
  145. //
  146. // Synopsis:
  147. //
  148. // Returns: Appropriate status code
  149. //
  150. // History: 04-May-96 HenryLee Created
  151. //
  152. //---------------------------------------------------------------
  153. STDMETHODIMP CSimpEnumSTATSTG::Skip (ULONG celt)
  154. {
  155. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::Skip()\n"));
  156. SCODE sc = STG_E_INVALIDFUNCTION;
  157. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::Skip()\n"));
  158. return sc;
  159. }
  160. //+--------------------------------------------------------------
  161. //
  162. // Member: CSimpEnumSTATSTG::Reset, public
  163. //
  164. // Synopsis:
  165. //
  166. // Returns: Appropriate status code
  167. //
  168. // History: 04-May-96 HenryLee Created
  169. //
  170. //---------------------------------------------------------------
  171. STDMETHODIMP CSimpEnumSTATSTG::Reset (void)
  172. {
  173. SCODE sc = S_OK;
  174. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::Reset()\n"));
  175. _pdflCurrent = _pdfl;
  176. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::Reset()\n"));
  177. return sc;
  178. }
  179. //+--------------------------------------------------------------
  180. //
  181. // Member: CSimpEnumSTATSTG::Clone, public
  182. //
  183. // Synopsis:
  184. //
  185. // Returns: Appropriate status code
  186. //
  187. // History: 04-May-96 HenryLee Created
  188. //
  189. //---------------------------------------------------------------
  190. STDMETHODIMP CSimpEnumSTATSTG::Clone (IEnumSTATSTG **ppenum)
  191. {
  192. SCODE sc = S_OK;
  193. simpDebugOut((DEB_TRACE, "In CSimpEnumSTATSTG::Clone()\n"));
  194. if (ppenum == NULL)
  195. return STG_E_INVALIDPARAMETER;
  196. if ((*ppenum = new CSimpEnumSTATSTG (_pdfl, _pdflCurrent)) == NULL)
  197. sc = STG_E_INSUFFICIENTMEMORY;
  198. simpDebugOut((DEB_TRACE, "Out CSimpEnumSTATSTG::Clone()\n"));
  199. return sc;
  200. }