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.

332 lines
10 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. ULONG cRef = InterlockedIncrement(&m_cRef);
  83. DBGPRINT((DM_CONTROL, DL_LOW, TEXT("\t0x%08X %d -> %d"), this, cRef - 1, cRef ));
  84. return cRef;
  85. }
  86. ///////////////////////////////////////////////////////////////////////////////
  87. /* Function: DiskQuotaControlClassFactory::Release
  88. Description: Decrements object reference count. If count drops to 0,
  89. object is deleted.
  90. Arguments: None.
  91. Returns: New reference count value.
  92. Revision History:
  93. Date Description Programmer
  94. -------- --------------------------------------------------- ----------
  95. 05/22/96 Initial creation. BrianAu
  96. */
  97. ///////////////////////////////////////////////////////////////////////////////
  98. STDMETHODIMP_(ULONG)
  99. DiskQuotaControlClassFactory::Release(
  100. VOID
  101. )
  102. {
  103. DBGTRACE((DM_CONTROL, DL_LOW, TEXT("DiskQuotaControlClassFactory::Release")));
  104. ASSERT( 0 != m_cRef );
  105. ULONG cRef = InterlockedDecrement(&m_cRef);
  106. DBGPRINT((DM_CONTROL, DL_LOW, TEXT("\t0x%08X %d -> %d"), this, cRef + 1, m_cRef ));
  107. if ( 0 == cRef )
  108. {
  109. delete this;
  110. }
  111. return cRef;
  112. }
  113. ///////////////////////////////////////////////////////////////////////////////
  114. /* Function: DiskQuotaControlClassFactory::CreateInstance
  115. Description: Creates a new instance of a DiskQuotaControl object, returning
  116. a pointer to its IDiskQuotaControl interface.
  117. Arguments:
  118. pUnkOuter - Pointer to outer object's IUnknown interface for IUnknown
  119. delegation in support of aggregation. Aggregation is not supported
  120. by IDiskQuotaControl.
  121. riid - Reference to interface ID being requested.
  122. ppvOut - Address of interface pointer variable to accept interface
  123. pointer.
  124. Returns:
  125. NOERROR - Success.
  126. E_OUTOFMEMORY - Insufficient memory to create new object.
  127. E_NOINTERFACE - Requested interface not supported.
  128. E_INVALIDARG - ppvOut arg was NULL.
  129. CLASS_E_NOAGGREGATION - Aggregation was requested but is not supported.
  130. Revision History:
  131. Date Description Programmer
  132. -------- --------------------------------------------------- ----------
  133. 05/22/96 Initial creation. BrianAu
  134. 08/15/96 Added shell extension support. BrianAu
  135. 08/20/97 Added IDispatch support. BrianAu
  136. */
  137. ///////////////////////////////////////////////////////////////////////////////
  138. STDMETHODIMP
  139. DiskQuotaControlClassFactory::CreateInstance(
  140. LPUNKNOWN pUnkOuter,
  141. REFIID riid,
  142. LPVOID *ppvOut
  143. )
  144. {
  145. DBGTRACE((DM_CONTROL, DL_HIGH, TEXT("DiskQuotaControlClassFactory::CreateInstance")));
  146. DBGPRINTIID(DM_CONTROL, DL_HIGH, riid);
  147. HRESULT hr = E_NOINTERFACE;
  148. if (NULL == ppvOut)
  149. return E_INVALIDARG;
  150. *ppvOut = NULL;
  151. try
  152. {
  153. if (NULL != pUnkOuter && IID_IUnknown != riid)
  154. {
  155. hr = CLASS_E_NOAGGREGATION;
  156. }
  157. else if (IID_IClassFactory == riid)
  158. {
  159. *ppvOut = this;
  160. ((LPUNKNOWN)*ppvOut)->AddRef();
  161. hr = NOERROR;
  162. }
  163. else if (IID_IDiskQuotaControl == riid ||
  164. IID_IDispatch == riid ||
  165. IID_IUnknown == riid)
  166. {
  167. hr = Create_IDiskQuotaControl(riid, ppvOut);
  168. }
  169. }
  170. catch(CAllocException& e)
  171. {
  172. DBGERROR((TEXT("Insufficient memory exception")));
  173. hr = E_OUTOFMEMORY;
  174. }
  175. return hr;
  176. }
  177. ///////////////////////////////////////////////////////////////////////////////
  178. /* Function: DiskQuotaControlClassFactory::LockServer
  179. Description: Places/removes a lock on the DLL server. See OLE 2
  180. documentation of IClassFactory for details.
  181. Arguments:
  182. fLock - TRUE = Increment lock count, FALSE = Decrement lock count.
  183. Returns:
  184. S_OK - Success.
  185. S_FALSE - Lock count is already 0. Can't be decremented.
  186. Revision History:
  187. Date Description Programmer
  188. -------- --------------------------------------------------- ----------
  189. 05/22/96 Initial creation. BrianAu
  190. */
  191. ///////////////////////////////////////////////////////////////////////////////
  192. STDMETHODIMP
  193. DiskQuotaControlClassFactory::LockServer(
  194. BOOL fLock
  195. )
  196. {
  197. DBGTRACE((DM_CONTROL, DL_HIGH, TEXT("DiskQuotaControlClassFactory::LockServer")));
  198. HRESULT hr = S_OK;
  199. if (fLock)
  200. {
  201. //
  202. // Increment the lock count.
  203. //
  204. InterlockedIncrement(&g_cLockThisDll);
  205. }
  206. else
  207. {
  208. //
  209. // Decrement only if lock count is > 0.
  210. // Otherwise, it's an error.
  211. //
  212. LONG lLock = g_cLockThisDll - 1;
  213. if (0 <= lLock)
  214. {
  215. ASSERT( 0 != g_cLockThisDll );
  216. InterlockedDecrement(&g_cLockThisDll);
  217. }
  218. else
  219. hr = S_FALSE; // Lock count already at 0.
  220. }
  221. return hr;
  222. }
  223. ///////////////////////////////////////////////////////////////////////////////
  224. /* Function: DiskQuotaControlClassFactory::Create_IDiskQuotaControl
  225. Description: Creates a DiskQuotaControl object and returns a pointer
  226. to it's IDiskQuotaControl interface.
  227. Arguments:
  228. ppvOut - Address of interface pointer variable to receive the interface
  229. pointer.
  230. riid - Reference to interface ID requested.
  231. Returns:
  232. NOERROR - Success.
  233. Exceptions: OutOfMemory.
  234. Revision History:
  235. Date Description Programmer
  236. -------- --------------------------------------------------- ----------
  237. 08/15/96 Initial creation. BrianAu
  238. Broke code out of CreateInstance().
  239. 08/20/97 Added riid argument. BrianAu
  240. */
  241. ///////////////////////////////////////////////////////////////////////////////
  242. HRESULT
  243. DiskQuotaControlClassFactory::Create_IDiskQuotaControl(
  244. REFIID riid,
  245. LPVOID *ppvOut
  246. )
  247. {
  248. DBGTRACE((DM_CONTROL, DL_MID, TEXT("DiskQuotaControlClassFactory::Create_IDiskQuotaControl")));
  249. DBGASSERT((NULL != ppvOut));
  250. HRESULT hr = NOERROR;
  251. DiskQuotaControl *pController = new DiskQuotaControl;
  252. hr = pController->QueryInterface(riid, ppvOut);
  253. if (FAILED(hr))
  254. {
  255. delete pController;
  256. }
  257. return hr;
  258. }