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.

278 lines
8.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /* File: factory.cpp
  3. Description: Contains the member function definitions for class
  4. DiskQuotaUIClassFactory. 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. 02/04/98 Added creation of IComponent. BrianAu
  13. 06/25/98 Disabled MMC snapin code. BrianAu
  14. */
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #include "pch.h" // PCH
  17. #pragma hdrstop
  18. #include "factory.h"
  19. #include "extinit.h"
  20. #include "resource.h"
  21. #include "guidsp.h"
  22. //
  23. // Verify that build is UNICODE.
  24. //
  25. #if !defined(UNICODE)
  26. # error This module must be compiled UNICODE.
  27. #endif
  28. extern LONG g_cLockThisDll; // Supports LockServer().
  29. ///////////////////////////////////////////////////////////////////////////////
  30. /* Function: DiskQuotaUIClassFactory::QueryInterface
  31. Description: Retrieves a pointer to the IUnknown or IClassFactory
  32. interface. Recoginizes the IID_IUnknown and IID_IClassFactory
  33. interface IDs.
  34. Arguments:
  35. riid - Reference to requested interface ID.
  36. ppvOut - Address of interface pointer variable to accept interface ptr.
  37. Returns:
  38. NO_ERROR - Success.
  39. E_NOINTERFACE - Requested interface not supported.
  40. E_INVALIDARG - ppvOut argument was NULL.
  41. Revision History:
  42. Date Description Programmer
  43. -------- --------------------------------------------------- ----------
  44. 05/22/96 Initial creation. BrianAu
  45. 08/15/96 Added IShellPropSheetExt BrianAu
  46. */
  47. ///////////////////////////////////////////////////////////////////////////////
  48. STDMETHODIMP
  49. DiskQuotaUIClassFactory::QueryInterface(
  50. REFIID riid,
  51. LPVOID *ppvOut
  52. )
  53. {
  54. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::QueryInterface")));
  55. HRESULT hResult = E_NOINTERFACE;
  56. if (NULL == ppvOut)
  57. return E_INVALIDARG;
  58. *ppvOut = NULL;
  59. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  60. {
  61. *ppvOut = this;
  62. ((LPUNKNOWN)*ppvOut)->AddRef();
  63. hResult = NOERROR;
  64. }
  65. return hResult;
  66. }
  67. ///////////////////////////////////////////////////////////////////////////////
  68. /* Function: DiskQuotaUIClassFactory::AddRef
  69. Description: Increments object reference count.
  70. Arguments: None.
  71. Returns: New reference count value.
  72. Revision History:
  73. Date Description Programmer
  74. -------- --------------------------------------------------- ----------
  75. 05/22/96 Initial creation. BrianAu
  76. */
  77. ///////////////////////////////////////////////////////////////////////////////
  78. STDMETHODIMP_(ULONG)
  79. DiskQuotaUIClassFactory::AddRef(
  80. VOID
  81. )
  82. {
  83. ULONG cRef = InterlockedIncrement(&m_cRef);
  84. DBGPRINT((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::AddRef, 0x%08X %d -> %d"), this, cRef - 1, cRef ));
  85. return cRef;
  86. }
  87. ///////////////////////////////////////////////////////////////////////////////
  88. /* Function: DiskQuotaUIClassFactory::Release
  89. Description: Decrements object reference count. If count drops to 0,
  90. object is deleted.
  91. Arguments: None.
  92. Returns: New reference count value.
  93. Revision History:
  94. Date Description Programmer
  95. -------- --------------------------------------------------- ----------
  96. 05/22/96 Initial creation. BrianAu
  97. */
  98. ///////////////////////////////////////////////////////////////////////////////
  99. STDMETHODIMP_(ULONG)
  100. DiskQuotaUIClassFactory::Release(
  101. VOID
  102. )
  103. {
  104. ASSERT( 0 != m_cRef );
  105. ULONG cRef = InterlockedDecrement(&m_cRef);
  106. DBGPRINT((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::Release, 0x%08X %d -> %d"),
  107. this, cRef + 1, cRef));
  108. if ( 0 == cRef )
  109. {
  110. delete this;
  111. }
  112. return cRef;
  113. }
  114. ///////////////////////////////////////////////////////////////////////////////
  115. /* Function: DiskQuotaUIClassFactory::CreateInstance
  116. Description: Creates a new instance of a DiskQuotaControl object, returning
  117. a pointer to its IDiskQuotaControl interface.
  118. Arguments:
  119. pUnkOuter - Pointer to outer object's IUnknown interface for IUnknown
  120. delegation in support of aggregation. Aggregation is not supported
  121. by IDiskQuotaControl.
  122. riid - Reference to interface ID being requested.
  123. ppvOut - Address of interface pointer variable to accept interface
  124. pointer.
  125. Returns:
  126. NO_ERROR - Success.
  127. CLASS_E_NOAGGREGATION - Aggregation was requested but is not supported.
  128. E_OUTOFMEMORY - Insufficient memory to create new object.
  129. E_NOINTERFACE - Requested interface not supported.
  130. E_INVALIDARG - ppvOut arg was NULL.
  131. Revision History:
  132. Date Description Programmer
  133. -------- --------------------------------------------------- ----------
  134. 05/22/96 Initial creation. BrianAu
  135. 08/15/96 Added shell extension support. BrianAu
  136. */
  137. ///////////////////////////////////////////////////////////////////////////////
  138. STDMETHODIMP
  139. DiskQuotaUIClassFactory::CreateInstance(
  140. LPUNKNOWN pUnkOuter,
  141. REFIID riid,
  142. LPVOID *ppvOut
  143. )
  144. {
  145. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::CreateInstance")));
  146. HRESULT hResult = NO_ERROR;
  147. TCHAR szGUID[MAX_PATH];
  148. StringFromGUID2(riid, szGUID, ARRAYSIZE(szGUID));
  149. DBGPRINT((DM_COM, DL_HIGH, TEXT("CreateInstance: %s"), szGUID));
  150. if (NULL == ppvOut)
  151. return E_INVALIDARG;
  152. *ppvOut = NULL;
  153. try
  154. {
  155. if (NULL != pUnkOuter && IID_IUnknown != riid)
  156. {
  157. hResult = CLASS_E_NOAGGREGATION;
  158. }
  159. else
  160. {
  161. ShellExtInit *pExtInit = new ShellExtInit;
  162. pExtInit->AddRef();
  163. hResult = pExtInit->QueryInterface(riid, ppvOut);
  164. pExtInit->Release();
  165. }
  166. }
  167. catch(CAllocException& e)
  168. {
  169. hResult = E_OUTOFMEMORY;
  170. }
  171. return hResult;
  172. }
  173. ///////////////////////////////////////////////////////////////////////////////
  174. /* Function: DiskQuotaUIClassFactory::LockServer
  175. Description: Places/removes a lock on the DLL server. See OLE 2
  176. documentation of IClassFactory for details.
  177. Arguments:
  178. fLock - TRUE = Increment lock count, FALSE = Decrement lock count.
  179. Returns:
  180. S_OK - Success.
  181. S_FALSE - Lock count is already 0. Can't be decremented.
  182. Revision History:
  183. Date Description Programmer
  184. -------- --------------------------------------------------- ----------
  185. 05/22/96 Initial creation. BrianAu
  186. */
  187. ///////////////////////////////////////////////////////////////////////////////
  188. STDMETHODIMP
  189. DiskQuotaUIClassFactory::LockServer(
  190. BOOL fLock
  191. )
  192. {
  193. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::LockServer")));
  194. HRESULT hResult = S_OK;
  195. if (fLock)
  196. {
  197. //
  198. // Increment the lock count.
  199. //
  200. InterlockedIncrement(&g_cLockThisDll);
  201. }
  202. else
  203. {
  204. //
  205. // Decrement only if lock count is > 0.
  206. // Otherwise, it's an error.
  207. //
  208. LONG lLock = g_cLockThisDll - 1;
  209. if (0 <= lLock)
  210. {
  211. ASSERT( 0 != g_cLockThisDll );
  212. InterlockedDecrement(&g_cLockThisDll);
  213. }
  214. else
  215. hResult = S_FALSE; // Lock count already at 0.
  216. }
  217. return hResult;
  218. }