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.

341 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FaxRecipients.cpp
  5. Abstract:
  6. Implementation of Fax Recipients Collection
  7. Author:
  8. Iv Garber (IvG) Apr, 2000
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "FaxComEx.h"
  13. #include "FaxRecipients.h"
  14. //
  15. //====================== ADD & REMOVE ==================================
  16. //
  17. STDMETHODIMP
  18. CFaxRecipients::Add (
  19. /*[in]*/ BSTR bstrFaxNumber,
  20. /*[in,defaultvalue("")]*/ BSTR bstrName,
  21. /*[out, retval]*/ IFaxRecipient **ppRecipient
  22. )
  23. /*++
  24. Routine name : CFaxRecipients::Add
  25. Routine description:
  26. Add New Recipient to the Recipients Collection
  27. Author:
  28. Iv Garber (IvG), Apr, 2000
  29. Arguments:
  30. ppRecipient [out] - Ptr to the newly created Recipient
  31. Return Value:
  32. Standard HRESULT code
  33. --*/
  34. {
  35. HRESULT hr = S_OK;
  36. DBG_ENTER (_T("CFaxRecipients::Add"), hr);
  37. //
  38. // Check that we can write to the given pointer
  39. //
  40. if (::IsBadWritePtr(ppRecipient, sizeof(IFaxRecipient* )))
  41. {
  42. //
  43. // Got a bad return pointer
  44. //
  45. hr = E_POINTER;
  46. AtlReportError(CLSID_FaxRecipients,
  47. IDS_ERROR_INVALID_ARGUMENT,
  48. IID_IFaxRecipients,
  49. hr);
  50. CALL_FAIL(GENERAL_ERR, _T("::IsBadWritePtr()"), hr);
  51. return hr;
  52. }
  53. //
  54. // Fax Number should exist
  55. //
  56. if (::SysStringLen(bstrFaxNumber) < 1)
  57. {
  58. hr = E_INVALIDARG;
  59. AtlReportError(CLSID_FaxRecipients,
  60. IDS_ERROR_EMPTY_ARGUMENT,
  61. IID_IFaxRecipients,
  62. hr);
  63. CALL_FAIL(GENERAL_ERR, _T("::SysStringLen(bstrFaxNumber) < 1"), hr);
  64. return hr;
  65. }
  66. CComPtr<IFaxRecipient> pNewRecipient;
  67. hr = CFaxRecipient::Create(&pNewRecipient);
  68. if (FAILED(hr))
  69. {
  70. //
  71. // Failed to create Recipient object
  72. //
  73. AtlReportError(CLSID_FaxRecipients,
  74. IDS_ERROR_OPERATION_FAILED,
  75. IID_IFaxRecipients,
  76. hr);
  77. CALL_FAIL(GENERAL_ERR, _T("CFaxRecipient::Create()"), hr);
  78. return hr;
  79. }
  80. try
  81. {
  82. m_coll.push_back(pNewRecipient);
  83. }
  84. catch (exception &)
  85. {
  86. //
  87. // Failed to add the Recipient to the Collection
  88. //
  89. hr = E_OUTOFMEMORY;
  90. AtlReportError(CLSID_FaxRecipients,
  91. IDS_ERROR_OUTOFMEMORY,
  92. IID_IFaxRecipients,
  93. hr);
  94. CALL_FAIL(MEM_ERR, _T("m_coll.push_back()"), hr);
  95. return hr;
  96. }
  97. //
  98. // Put Fax Number
  99. //
  100. hr = pNewRecipient->put_FaxNumber(bstrFaxNumber);
  101. if (FAILED(hr))
  102. {
  103. AtlReportError(CLSID_FaxRecipients,
  104. IDS_ERROR_OPERATION_FAILED,
  105. IID_IFaxRecipients,
  106. hr);
  107. CALL_FAIL(MEM_ERR, _T("pNewRecipient->put_FaxNumber(bstrFaxNumber)"), hr);
  108. return hr;
  109. }
  110. //
  111. // Put Recipient's Name
  112. //
  113. hr = pNewRecipient->put_Name(bstrName);
  114. if (FAILED(hr))
  115. {
  116. AtlReportError(CLSID_FaxRecipients,
  117. IDS_ERROR_OPERATION_FAILED,
  118. IID_IFaxRecipients,
  119. hr);
  120. CALL_FAIL(MEM_ERR, _T("pNewRecipient->put_Name(bstrName)"), hr);
  121. return hr;
  122. }
  123. //
  124. // Additional AddRef() to prevent death of the Recipient
  125. //
  126. (*pNewRecipient).AddRef();
  127. pNewRecipient.CopyTo(ppRecipient);
  128. return hr;
  129. };
  130. STDMETHODIMP
  131. CFaxRecipients::Remove (
  132. /*[in]*/ long lIndex
  133. )
  134. /*++
  135. Routine name : CFaxRecipients::Remove
  136. Routine description:
  137. Remove Recipient at given index from the Collection
  138. Author:
  139. Iv Garber (IvG), Apr, 2000
  140. Arguments:
  141. lIndex [in] - Index of the Recipient to Remove
  142. Return Value:
  143. Standard HRESULT code
  144. --*/
  145. {
  146. HRESULT hr = S_OK;
  147. DBG_ENTER (_T("CFaxRecipients::Remove"), hr, _T("%d"), lIndex);
  148. if (lIndex < 1 || lIndex > m_coll.size())
  149. {
  150. //
  151. // Invalid Index
  152. //
  153. hr = E_INVALIDARG;
  154. AtlReportError(CLSID_FaxRecipients,
  155. IDS_ERROR_OUTOFRANGE,
  156. IID_IFaxRecipients,
  157. hr);
  158. CALL_FAIL(GENERAL_ERR, _T("lIndex > m_coll.size()"), hr);
  159. return hr;
  160. }
  161. ContainerType::iterator it;
  162. it = m_coll.begin() + lIndex - 1;
  163. hr = (*it)->Release();
  164. if (FAILED(hr))
  165. {
  166. //
  167. // Failed to Release the Interface
  168. //
  169. AtlReportError(CLSID_FaxRecipients,
  170. IDS_ERROR_OPERATION_FAILED,
  171. IID_IFaxRecipients,
  172. hr);
  173. CALL_FAIL(GENERAL_ERR, _T("Release()"), hr);
  174. return hr;
  175. }
  176. try
  177. {
  178. m_coll.erase(it);
  179. }
  180. catch(exception &)
  181. {
  182. //
  183. // Failed to remove the Recipient from the Collection
  184. //
  185. hr = E_OUTOFMEMORY;
  186. AtlReportError(CLSID_FaxRecipients,
  187. IDS_ERROR_OUTOFMEMORY,
  188. IID_IFaxRecipients,
  189. hr);
  190. CALL_FAIL(MEM_ERR, _T("m_coll.erase()"), hr);
  191. return hr;
  192. }
  193. return hr;
  194. };
  195. //
  196. //====================== CREATE ==================================
  197. //
  198. HRESULT
  199. CFaxRecipients::Create (
  200. IFaxRecipients **ppRecipients
  201. )
  202. /*++
  203. Routine name : CFaxRecipients::Create
  204. Routine description:
  205. Static function to Create Recipients Collection
  206. Author:
  207. Iv Garber (IvG), Apr, 2000
  208. Arguments:
  209. ppRecipients [out] - the resulting collection
  210. Return Value:
  211. Standard HRESULT code
  212. --*/
  213. {
  214. CComObject<CFaxRecipients> *pClass;
  215. HRESULT hr;
  216. DBG_ENTER (_T("CFaxRecipients::Create"), hr);
  217. hr = CComObject<CFaxRecipients>::CreateInstance(&pClass);
  218. if (FAILED(hr))
  219. {
  220. //
  221. // Failed to create Instance
  222. //
  223. CALL_FAIL(GENERAL_ERR, _T("CComObject<CFaxRecipients>::CreateInstance()"), hr);
  224. return hr;
  225. }
  226. hr = pClass->QueryInterface(__uuidof(IFaxRecipients), (void **) ppRecipients);
  227. if (FAILED(hr))
  228. {
  229. //
  230. // Failed to Query Fax Recipients Interface
  231. //
  232. CALL_FAIL(GENERAL_ERR, _T("QueryInterface()"), hr);
  233. return hr;
  234. }
  235. return hr;
  236. }
  237. //
  238. //==================== INTERFACE SUPPORT ERROR INFO =====================
  239. //
  240. STDMETHODIMP
  241. CFaxRecipients::InterfaceSupportsErrorInfo (
  242. REFIID riid
  243. )
  244. /*++
  245. Routine name : CFaxRecipients::InterfaceSupportsErrorInfo
  246. Routine description:
  247. ATL's implementation of Support Error Info
  248. Author:
  249. Iv Garber (IvG), Apr, 2000
  250. Arguments:
  251. riid [in] - Interface ID
  252. Return Value:
  253. Standard HRESULT code
  254. --*/
  255. {
  256. static const IID* arr[] =
  257. {
  258. &IID_IFaxRecipients
  259. };
  260. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  261. {
  262. if (InlineIsEqualGUID(*arr[i],riid))
  263. return S_OK;
  264. }
  265. return S_FALSE;
  266. }