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.

311 lines
8.1 KiB

  1. // --------------------------------------------------------------------------------
  2. // EnumProp.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include "dllmain.h"
  7. #include "enumprop.h"
  8. #include "olealloc.h"
  9. #include "demand.h"
  10. // ---------------------------------------------------------------------------
  11. // CMimeEnumProperties::CMimeEnumProperties
  12. // ---------------------------------------------------------------------------
  13. CMimeEnumProperties::CMimeEnumProperties(void)
  14. {
  15. DllAddRef();
  16. m_cRef = 1;
  17. m_ulIndex = 0;
  18. m_cProps = 0;
  19. m_prgProp = NULL;
  20. InitializeCriticalSection(&m_cs);
  21. }
  22. // ---------------------------------------------------------------------------
  23. // CMimeEnumProperties::~CMimeEnumProperties
  24. // ---------------------------------------------------------------------------
  25. CMimeEnumProperties::~CMimeEnumProperties(void)
  26. {
  27. g_pMoleAlloc->FreeEnumPropertyArray(m_cProps, m_prgProp, TRUE);
  28. DeleteCriticalSection(&m_cs);
  29. DllRelease();
  30. }
  31. // ---------------------------------------------------------------------------
  32. // CMimeEnumProperties::QueryInterface
  33. // ---------------------------------------------------------------------------
  34. STDMETHODIMP CMimeEnumProperties::QueryInterface(REFIID riid, LPVOID *ppv)
  35. {
  36. // check params
  37. if (ppv == NULL)
  38. return TrapError(E_INVALIDARG);
  39. // Find IID
  40. if (IID_IUnknown == riid)
  41. *ppv = (IUnknown *)(IMimeEnumProperties *)this;
  42. else if (IID_IMimeEnumProperties == riid)
  43. *ppv = (IMimeEnumProperties *)this;
  44. else
  45. {
  46. *ppv = NULL;
  47. return TrapError(E_NOINTERFACE);
  48. }
  49. // AddRef It
  50. ((IUnknown *)*ppv)->AddRef();
  51. // Done
  52. return S_OK;
  53. }
  54. // ---------------------------------------------------------------------------
  55. // CMimeEnumProperties::AddRef
  56. // ---------------------------------------------------------------------------
  57. STDMETHODIMP_(ULONG) CMimeEnumProperties::AddRef(void)
  58. {
  59. return (ULONG)InterlockedIncrement(&m_cRef);
  60. }
  61. // ---------------------------------------------------------------------------
  62. // CMimeEnumProperties::Release
  63. // ---------------------------------------------------------------------------
  64. STDMETHODIMP_(ULONG) CMimeEnumProperties::Release(void)
  65. {
  66. LONG cRef = InterlockedDecrement(&m_cRef);
  67. if (0 == cRef)
  68. delete this;
  69. return (ULONG)cRef;
  70. }
  71. // ---------------------------------------------------------------------------
  72. // CMimeEnumProperties::Next
  73. // ---------------------------------------------------------------------------
  74. STDMETHODIMP CMimeEnumProperties::Next(ULONG cWanted, LPENUMPROPERTY prgProp, ULONG *pcFetched)
  75. {
  76. // Locals
  77. HRESULT hr=S_OK;
  78. ULONG cFetch=0,
  79. ulIndex=0;
  80. // Thread Safety
  81. EnterCriticalSection(&m_cs);
  82. // Init
  83. if (pcFetched)
  84. *pcFetched = 0;
  85. // No Internal Formats
  86. if (NULL == m_prgProp || NULL == prgProp)
  87. goto exit;
  88. // Compute number to fetch
  89. cFetch = min(cWanted, m_cProps - m_ulIndex);
  90. if (0 == cFetch)
  91. goto exit;
  92. // Init the array
  93. ZeroMemory(prgProp, sizeof(ENUMPROPERTY) * cWanted);
  94. // Copy cWanted
  95. for (ulIndex=0; ulIndex<cFetch; ulIndex++)
  96. {
  97. // Set the information
  98. prgProp[ulIndex].hRow = m_prgProp[m_ulIndex].hRow;
  99. // Set dwPropId
  100. prgProp[ulIndex].dwPropId = m_prgProp[m_ulIndex].dwPropId;
  101. // Not NONAME
  102. if (m_prgProp[m_ulIndex].pszName)
  103. {
  104. // Dup It
  105. CHECKALLOC(prgProp[ulIndex].pszName = PszDupA(m_prgProp[m_ulIndex].pszName));
  106. }
  107. // Goto Next
  108. m_ulIndex++;
  109. }
  110. // Return fetced ?
  111. if (pcFetched)
  112. *pcFetched = cFetch;
  113. exit:
  114. // Failure
  115. if (FAILED(hr) && prgProp)
  116. g_pMoleAlloc->FreeEnumPropertyArray(cFetch, prgProp, FALSE);
  117. // Thread Safety
  118. LeaveCriticalSection(&m_cs);
  119. // Done
  120. return (cFetch == cWanted) ? S_OK : S_FALSE;
  121. }
  122. // ---------------------------------------------------------------------------
  123. // CMimeEnumProperties::Skip
  124. // ---------------------------------------------------------------------------
  125. STDMETHODIMP CMimeEnumProperties::Skip(ULONG cSkip)
  126. {
  127. // Locals
  128. HRESULT hr=S_OK;
  129. // Thread Safety
  130. EnterCriticalSection(&m_cs);
  131. // Can we do it...
  132. if (((m_ulIndex + cSkip) >= m_cProps) || NULL == m_prgProp)
  133. {
  134. hr = S_FALSE;
  135. goto exit;
  136. }
  137. // Skip
  138. m_ulIndex += cSkip;
  139. exit:
  140. // Thread Safety
  141. LeaveCriticalSection(&m_cs);
  142. // Done
  143. return hr;
  144. }
  145. // ---------------------------------------------------------------------------
  146. // CMimeEnumProperties::Reset
  147. // ---------------------------------------------------------------------------
  148. STDMETHODIMP CMimeEnumProperties::Reset(void)
  149. {
  150. // Thread Safety
  151. EnterCriticalSection(&m_cs);
  152. // Reset
  153. m_ulIndex = 0;
  154. // Thread Safety
  155. LeaveCriticalSection(&m_cs);
  156. // Done
  157. return S_OK;
  158. }
  159. // ---------------------------------------------------------------------------
  160. // CMimeEnumProperties::Clone
  161. // ---------------------------------------------------------------------------
  162. STDMETHODIMP CMimeEnumProperties::Clone(IMimeEnumProperties **ppEnum)
  163. {
  164. // Locals
  165. HRESULT hr=S_OK;
  166. CMimeEnumProperties *pEnum=NULL;
  167. // check params
  168. if (NULL == ppEnum)
  169. return TrapError(E_INVALIDARG);
  170. // Init
  171. *ppEnum = NULL;
  172. // Thread Safety
  173. EnterCriticalSection(&m_cs);
  174. // Allocate
  175. CHECKALLOC(pEnum = new CMimeEnumProperties());
  176. // Init
  177. CHECKHR(hr = pEnum->HrInit(m_ulIndex, m_cProps, m_prgProp, TRUE));
  178. // Retrun
  179. (*ppEnum) = pEnum;
  180. (*ppEnum)->AddRef();
  181. exit:
  182. // Cleanup
  183. SafeRelease(pEnum);
  184. // Thread Safety
  185. LeaveCriticalSection(&m_cs);
  186. // Done
  187. return hr;
  188. }
  189. // ---------------------------------------------------------------------------
  190. // CMimeEnumProperties::Count
  191. // ---------------------------------------------------------------------------
  192. STDMETHODIMP CMimeEnumProperties::Count(ULONG *pcProps)
  193. {
  194. // check params
  195. if (NULL == pcProps)
  196. return TrapError(E_INVALIDARG);
  197. // Thread Safety
  198. EnterCriticalSection(&m_cs);
  199. // Set return
  200. *pcProps = m_cProps;
  201. // Thread Safety
  202. LeaveCriticalSection(&m_cs);
  203. // Done
  204. return S_OK;
  205. }
  206. // ---------------------------------------------------------------------------
  207. // CMimeEnumProperties::HrInit
  208. // ---------------------------------------------------------------------------
  209. HRESULT CMimeEnumProperties::HrInit(ULONG ulIndex, ULONG cProps, LPENUMPROPERTY prgProp, BOOL fDupArray)
  210. {
  211. // Locals
  212. HRESULT hr=S_OK;
  213. ULONG i;
  214. // Thread Safety
  215. EnterCriticalSection(&m_cs);
  216. // Save Lines
  217. m_ulIndex = ulIndex;
  218. m_cProps = cProps;
  219. // Are there lines ...
  220. if (m_cProps)
  221. {
  222. // Duplicate the Array
  223. if (fDupArray)
  224. {
  225. // Allocate memory
  226. CHECKALLOC(m_prgProp = (LPENUMPROPERTY)g_pMalloc->Alloc(m_cProps * sizeof(ENUMPROPERTY)));
  227. // ZeroInit
  228. ZeroMemory(m_prgProp, sizeof(ENUMPROPERTY) * m_cProps);
  229. // Loop
  230. for (i=0; i<m_cProps; i++)
  231. {
  232. // Set the information
  233. m_prgProp[i].hRow = prgProp[i].hRow;
  234. // Set dwPropId
  235. m_prgProp[i].dwPropId = prgProp[i].dwPropId;
  236. // Not NONAME
  237. if (prgProp[i].pszName)
  238. {
  239. // Dup It
  240. CHECKALLOC(m_prgProp[i].pszName = PszDupA(prgProp[i].pszName));
  241. }
  242. }
  243. }
  244. // Otherwise, just assume this array
  245. else
  246. m_prgProp = prgProp;
  247. }
  248. exit:
  249. // Thread Safety
  250. LeaveCriticalSection(&m_cs);
  251. // Done
  252. return hr;
  253. }