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.

333 lines
9.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /* File: factory.cpp
  3. Description: Contains the member function definitions for class
  4. DiskQuotaControlClassFactory. The class factory object generates
  5. new instances of DiskQuotaControl objects. The object implements
  6. IClassFactory.
  7. Revision History:
  8. Date Description Programmer
  9. -------- --------------------------------------------------- ----------
  10. 05/22/96 Initial creation. BrianAu
  11. 08/15/96 Added shell extension support. BrianAu
  12. */
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include "pch.h" // PCH
  15. #pragma hdrstop
  16. #include "dskquota.h"
  17. #include "control.h"
  18. #include "factory.h"
  19. //
  20. // Verify that build is UNICODE.
  21. //
  22. #if !defined(UNICODE)
  23. # error This module must be compiled UNICODE.
  24. #endif
  25. extern LONG g_cLockThisDll; // Supports LockServer().
  26. ///////////////////////////////////////////////////////////////////////////////
  27. /* Function: DiskQuotaControlClassFactory::QueryInterface
  28. Description: Retrieves a pointer to the IUnknown or IClassFactory
  29. interface. Recoginizes the IID_IUnknown and IID_IClassFactory
  30. interface IDs.
  31. Arguments:
  32. riid - Reference to requested interface ID.
  33. ppvOut - Address of interface pointer variable to accept interface ptr.
  34. Returns:
  35. NOERROR - Success.
  36. E_NOINTERFACE - Requested interface not supported.
  37. E_INVALIDARG - ppvOut argument was NULL.
  38. Revision History:
  39. Date Description Programmer
  40. -------- --------------------------------------------------- ----------
  41. 05/22/96 Initial creation. BrianAu
  42. 08/15/96 Added IShellPropSheetExt BrianAu
  43. */
  44. ///////////////////////////////////////////////////////////////////////////////
  45. STDMETHODIMP
  46. DiskQuotaControlClassFactory::QueryInterface(
  47. REFIID riid,
  48. LPVOID *ppvOut
  49. )
  50. {
  51. DBGTRACE((DM_CONTROL, DL_MID, TEXT("DiskQuotaControlClassFactory::QueryInterface")));
  52. DBGPRINTIID(DM_CONTROL, DL_MID, riid);
  53. HRESULT hr = E_NOINTERFACE;
  54. if (NULL == ppvOut)
  55. return E_INVALIDARG;
  56. *ppvOut = NULL;
  57. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  58. {
  59. *ppvOut = this;
  60. ((LPUNKNOWN)*ppvOut)->AddRef();
  61. hr = NOERROR;
  62. }
  63. return hr;
  64. }
  65. ///////////////////////////////////////////////////////////////////////////////
  66. /* Function: DiskQuotaControlClassFactory::AddRef
  67. Description: Increments object reference count.
  68. Arguments: None.
  69. Returns: New reference count value.
  70. Revision History:
  71. Date Description Programmer
  72. -------- --------------------------------------------------- ----------
  73. 05/22/96 Initial creation. BrianAu
  74. */
  75. ///////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP_(ULONG)
  77. DiskQuotaControlClassFactory::AddRef(
  78. VOID
  79. )
  80. {
  81. DBGTRACE((DM_CONTROL, DL_LOW, TEXT("DiskQuotaControlClassFactory::AddRef")));
  82. DBGPRINT((DM_CONTROL, DL_LOW, TEXT("\t0x%08X %d -> %d"),
  83. this, m_cRef, m_cRef + 1));
  84. ULONG ulReturn = m_cRef + 1;
  85. InterlockedIncrement(&m_cRef);
  86. return ulReturn;
  87. }
  88. ///////////////////////////////////////////////////////////////////////////////
  89. /* Function: DiskQuotaControlClassFactory::Release
  90. Description: Decrements object reference count. If count drops to 0,
  91. object is deleted.
  92. Arguments: None.
  93. Returns: New reference count value.
  94. Revision History:
  95. Date Description Programmer
  96. -------- --------------------------------------------------- ----------
  97. 05/22/96 Initial creation. BrianAu
  98. */
  99. ///////////////////////////////////////////////////////////////////////////////
  100. STDMETHODIMP_(ULONG)
  101. DiskQuotaControlClassFactory::Release(
  102. VOID
  103. )
  104. {
  105. DBGTRACE((DM_CONTROL, DL_LOW, TEXT("DiskQuotaControlClassFactory::Release")));
  106. DBGPRINT((DM_CONTROL, DL_LOW, TEXT("\t0x%08X %d -> %d"),
  107. this, m_cRef, m_cRef - 1));
  108. ULONG ulReturn = m_cRef - 1;
  109. if (InterlockedDecrement(&m_cRef) == 0)
  110. {
  111. delete this;
  112. ulReturn = 0;
  113. }
  114. return ulReturn;
  115. }
  116. ///////////////////////////////////////////////////////////////////////////////
  117. /* Function: DiskQuotaControlClassFactory::CreateInstance
  118. Description: Creates a new instance of a DiskQuotaControl object, returning
  119. a pointer to its IDiskQuotaControl interface.
  120. Arguments:
  121. pUnkOuter - Pointer to outer object's IUnknown interface for IUnknown
  122. delegation in support of aggregation. Aggregation is not supported
  123. by IDiskQuotaControl.
  124. riid - Reference to interface ID being requested.
  125. ppvOut - Address of interface pointer variable to accept interface
  126. pointer.
  127. Returns:
  128. NOERROR - Success.
  129. E_OUTOFMEMORY - Insufficient memory to create new object.
  130. E_NOINTERFACE - Requested interface not supported.
  131. E_INVALIDARG - ppvOut arg was NULL.
  132. CLASS_E_NOAGGREGATION - Aggregation was requested but is not supported.
  133. Revision History:
  134. Date Description Programmer
  135. -------- --------------------------------------------------- ----------
  136. 05/22/96 Initial creation. BrianAu
  137. 08/15/96 Added shell extension support. BrianAu
  138. 08/20/97 Added IDispatch support. BrianAu
  139. */
  140. ///////////////////////////////////////////////////////////////////////////////
  141. STDMETHODIMP
  142. DiskQuotaControlClassFactory::CreateInstance(
  143. LPUNKNOWN pUnkOuter,
  144. REFIID riid,
  145. LPVOID *ppvOut
  146. )
  147. {
  148. DBGTRACE((DM_CONTROL, DL_HIGH, TEXT("DiskQuotaControlClassFactory::CreateInstance")));
  149. DBGPRINTIID(DM_CONTROL, DL_HIGH, riid);
  150. HRESULT hr = E_NOINTERFACE;
  151. if (NULL == ppvOut)
  152. return E_INVALIDARG;
  153. *ppvOut = NULL;
  154. try
  155. {
  156. if (NULL != pUnkOuter && IID_IUnknown != riid)
  157. {
  158. hr = CLASS_E_NOAGGREGATION;
  159. }
  160. else if (IID_IClassFactory == riid)
  161. {
  162. *ppvOut = this;
  163. ((LPUNKNOWN)*ppvOut)->AddRef();
  164. hr = NOERROR;
  165. }
  166. else if (IID_IDiskQuotaControl == riid ||
  167. IID_IDispatch == riid ||
  168. IID_IUnknown == riid)
  169. {
  170. hr = Create_IDiskQuotaControl(riid, ppvOut);
  171. }
  172. }
  173. catch(CAllocException& e)
  174. {
  175. DBGERROR((TEXT("Insufficient memory exception")));
  176. hr = E_OUTOFMEMORY;
  177. }
  178. return hr;
  179. }
  180. ///////////////////////////////////////////////////////////////////////////////
  181. /* Function: DiskQuotaControlClassFactory::LockServer
  182. Description: Places/removes a lock on the DLL server. See OLE 2
  183. documentation of IClassFactory for details.
  184. Arguments:
  185. fLock - TRUE = Increment lock count, FALSE = Decrement lock count.
  186. Returns:
  187. S_OK - Success.
  188. S_FALSE - Lock count is already 0. Can't be decremented.
  189. Revision History:
  190. Date Description Programmer
  191. -------- --------------------------------------------------- ----------
  192. 05/22/96 Initial creation. BrianAu
  193. */
  194. ///////////////////////////////////////////////////////////////////////////////
  195. STDMETHODIMP
  196. DiskQuotaControlClassFactory::LockServer(
  197. BOOL fLock
  198. )
  199. {
  200. DBGTRACE((DM_CONTROL, DL_HIGH, TEXT("DiskQuotaControlClassFactory::LockServer")));
  201. HRESULT hr = S_OK;
  202. if (fLock)
  203. {
  204. //
  205. // Increment the lock count.
  206. //
  207. InterlockedIncrement(&g_cLockThisDll);
  208. }
  209. else
  210. {
  211. //
  212. // Decrement only if lock count is > 0.
  213. // Otherwise, it's an error.
  214. //
  215. LONG lLock = g_cLockThisDll - 1;
  216. if (0 <= lLock)
  217. {
  218. InterlockedDecrement(&g_cLockThisDll);
  219. }
  220. else
  221. hr = S_FALSE; // Lock count already at 0.
  222. }
  223. return hr;
  224. }
  225. ///////////////////////////////////////////////////////////////////////////////
  226. /* Function: DiskQuotaControlClassFactory::Create_IDiskQuotaControl
  227. Description: Creates a DiskQuotaControl object and returns a pointer
  228. to it's IDiskQuotaControl interface.
  229. Arguments:
  230. ppvOut - Address of interface pointer variable to receive the interface
  231. pointer.
  232. riid - Reference to interface ID requested.
  233. Returns:
  234. NOERROR - Success.
  235. Exceptions: OutOfMemory.
  236. Revision History:
  237. Date Description Programmer
  238. -------- --------------------------------------------------- ----------
  239. 08/15/96 Initial creation. BrianAu
  240. Broke code out of CreateInstance().
  241. 08/20/97 Added riid argument. BrianAu
  242. */
  243. ///////////////////////////////////////////////////////////////////////////////
  244. HRESULT
  245. DiskQuotaControlClassFactory::Create_IDiskQuotaControl(
  246. REFIID riid,
  247. LPVOID *ppvOut
  248. )
  249. {
  250. DBGTRACE((DM_CONTROL, DL_MID, TEXT("DiskQuotaControlClassFactory::Create_IDiskQuotaControl")));
  251. DBGASSERT((NULL != ppvOut));
  252. HRESULT hr = NOERROR;
  253. DiskQuotaControl *pController = new DiskQuotaControl;
  254. hr = pController->QueryInterface(riid, ppvOut);
  255. if (FAILED(hr))
  256. {
  257. delete pController;
  258. }
  259. return hr;
  260. }