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.

364 lines
10 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 "snapin.h"
  21. #include "resource.h"
  22. #include "guidsp.h"
  23. //
  24. // Verify that build is UNICODE.
  25. //
  26. #if !defined(UNICODE)
  27. # error This module must be compiled UNICODE.
  28. #endif
  29. extern LONG g_cLockThisDll; // Supports LockServer().
  30. ///////////////////////////////////////////////////////////////////////////////
  31. /* Function: DiskQuotaUIClassFactory::QueryInterface
  32. Description: Retrieves a pointer to the IUnknown or IClassFactory
  33. interface. Recoginizes the IID_IUnknown and IID_IClassFactory
  34. interface IDs.
  35. Arguments:
  36. riid - Reference to requested interface ID.
  37. ppvOut - Address of interface pointer variable to accept interface ptr.
  38. Returns:
  39. NO_ERROR - Success.
  40. E_NOINTERFACE - Requested interface not supported.
  41. E_INVALIDARG - ppvOut argument was NULL.
  42. Revision History:
  43. Date Description Programmer
  44. -------- --------------------------------------------------- ----------
  45. 05/22/96 Initial creation. BrianAu
  46. 08/15/96 Added IShellPropSheetExt BrianAu
  47. */
  48. ///////////////////////////////////////////////////////////////////////////////
  49. STDMETHODIMP
  50. DiskQuotaUIClassFactory::QueryInterface(
  51. REFIID riid,
  52. LPVOID *ppvOut
  53. )
  54. {
  55. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::QueryInterface")));
  56. HRESULT hResult = E_NOINTERFACE;
  57. if (NULL == ppvOut)
  58. return E_INVALIDARG;
  59. *ppvOut = NULL;
  60. if (IID_IUnknown == riid || IID_IClassFactory == riid)
  61. {
  62. *ppvOut = this;
  63. ((LPUNKNOWN)*ppvOut)->AddRef();
  64. hResult = NOERROR;
  65. }
  66. return hResult;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////
  69. /* Function: DiskQuotaUIClassFactory::AddRef
  70. Description: Increments object reference count.
  71. Arguments: None.
  72. Returns: New reference count value.
  73. Revision History:
  74. Date Description Programmer
  75. -------- --------------------------------------------------- ----------
  76. 05/22/96 Initial creation. BrianAu
  77. */
  78. ///////////////////////////////////////////////////////////////////////////////
  79. STDMETHODIMP_(ULONG)
  80. DiskQuotaUIClassFactory::AddRef(
  81. VOID
  82. )
  83. {
  84. ULONG ulReturn = m_cRef + 1;
  85. DBGPRINT((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::AddRef, 0x%08X %d -> %d"),
  86. this, ulReturn - 1, ulReturn));
  87. InterlockedIncrement(&m_cRef);
  88. return ulReturn;
  89. }
  90. ///////////////////////////////////////////////////////////////////////////////
  91. /* Function: DiskQuotaUIClassFactory::Release
  92. Description: Decrements object reference count. If count drops to 0,
  93. object is deleted.
  94. Arguments: None.
  95. Returns: New reference count value.
  96. Revision History:
  97. Date Description Programmer
  98. -------- --------------------------------------------------- ----------
  99. 05/22/96 Initial creation. BrianAu
  100. */
  101. ///////////////////////////////////////////////////////////////////////////////
  102. STDMETHODIMP_(ULONG)
  103. DiskQuotaUIClassFactory::Release(
  104. VOID
  105. )
  106. {
  107. ULONG ulReturn = m_cRef - 1;
  108. DBGPRINT((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::Release, 0x%08X %d -> %d"),
  109. this, ulReturn + 1, ulReturn));
  110. if (InterlockedDecrement(&m_cRef) == 0)
  111. {
  112. delete this;
  113. ulReturn = 0;
  114. }
  115. return ulReturn;
  116. }
  117. ///////////////////////////////////////////////////////////////////////////////
  118. /* Function: DiskQuotaUIClassFactory::CreateInstance
  119. Description: Creates a new instance of a DiskQuotaControl object, returning
  120. a pointer to its IDiskQuotaControl interface.
  121. Arguments:
  122. pUnkOuter - Pointer to outer object's IUnknown interface for IUnknown
  123. delegation in support of aggregation. Aggregation is not supported
  124. by IDiskQuotaControl.
  125. riid - Reference to interface ID being requested.
  126. ppvOut - Address of interface pointer variable to accept interface
  127. pointer.
  128. Returns:
  129. NO_ERROR - Success.
  130. CLASS_E_NOAGGREGATION - Aggregation was requested but is not supported.
  131. E_OUTOFMEMORY - Insufficient memory to create new object.
  132. E_NOINTERFACE - Requested interface not supported.
  133. E_INVALIDARG - ppvOut arg was NULL.
  134. Revision History:
  135. Date Description Programmer
  136. -------- --------------------------------------------------- ----------
  137. 05/22/96 Initial creation. BrianAu
  138. 08/15/96 Added shell extension support. BrianAu
  139. */
  140. ///////////////////////////////////////////////////////////////////////////////
  141. STDMETHODIMP
  142. DiskQuotaUIClassFactory::CreateInstance(
  143. LPUNKNOWN pUnkOuter,
  144. REFIID riid,
  145. LPVOID *ppvOut
  146. )
  147. {
  148. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::CreateInstance")));
  149. HRESULT hResult = NO_ERROR;
  150. TCHAR szGUID[MAX_PATH];
  151. StringFromGUID2(riid, szGUID, ARRAYSIZE(szGUID));
  152. DBGPRINT((DM_COM, DL_HIGH, TEXT("CreateInstance: %s"), szGUID));
  153. if (NULL == ppvOut)
  154. return E_INVALIDARG;
  155. *ppvOut = NULL;
  156. try
  157. {
  158. if (NULL != pUnkOuter && IID_IUnknown != riid)
  159. {
  160. hResult = CLASS_E_NOAGGREGATION;
  161. }
  162. else
  163. {
  164. InstanceProxy *pip = new InstanceProxy;
  165. hResult = pip->QueryInterface(riid, ppvOut);
  166. if (IID_IUnknown != riid || FAILED(hResult))
  167. {
  168. //
  169. // Either caller requested something other than IUnknown
  170. // or QI failed. We can delete the instance proxy.
  171. // It's only necessary to keep around if the caller asked
  172. // for IUnknown.
  173. //
  174. delete pip;
  175. }
  176. }
  177. }
  178. catch(CAllocException& e)
  179. {
  180. hResult = E_OUTOFMEMORY;
  181. }
  182. return hResult;
  183. }
  184. ///////////////////////////////////////////////////////////////////////////////
  185. /* Function: DiskQuotaUIClassFactory::LockServer
  186. Description: Places/removes a lock on the DLL server. See OLE 2
  187. documentation of IClassFactory for details.
  188. Arguments:
  189. fLock - TRUE = Increment lock count, FALSE = Decrement lock count.
  190. Returns:
  191. S_OK - Success.
  192. S_FALSE - Lock count is already 0. Can't be decremented.
  193. Revision History:
  194. Date Description Programmer
  195. -------- --------------------------------------------------- ----------
  196. 05/22/96 Initial creation. BrianAu
  197. */
  198. ///////////////////////////////////////////////////////////////////////////////
  199. STDMETHODIMP
  200. DiskQuotaUIClassFactory::LockServer(
  201. BOOL fLock
  202. )
  203. {
  204. DBGTRACE((DM_COM, DL_HIGH, TEXT("DiskQuotaUIClassFactory::LockServer")));
  205. HRESULT hResult = S_OK;
  206. if (fLock)
  207. {
  208. //
  209. // Increment the lock count.
  210. //
  211. InterlockedIncrement(&g_cLockThisDll);
  212. }
  213. else
  214. {
  215. //
  216. // Decrement only if lock count is > 0.
  217. // Otherwise, it's an error.
  218. //
  219. LONG lLock = g_cLockThisDll - 1;
  220. if (0 <= lLock)
  221. {
  222. InterlockedDecrement(&g_cLockThisDll);
  223. }
  224. else
  225. hResult = S_FALSE; // Lock count already at 0.
  226. }
  227. return hResult;
  228. }
  229. HRESULT
  230. InstanceProxy::QueryInterface(
  231. REFIID riid,
  232. LPVOID *ppvOut
  233. )
  234. {
  235. HRESULT hResult = E_NOINTERFACE;
  236. DBGTRACE((DM_COM, DL_HIGH, TEXT("InstanceProxy::QueryInterface")));
  237. if (NULL == ppvOut)
  238. return E_INVALIDARG;
  239. *ppvOut = NULL;
  240. if (IID_IUnknown == riid)
  241. {
  242. DBGPRINT((DM_COM, DL_MID, TEXT("Requested IID_IUnknown")));
  243. *ppvOut = this;
  244. ((LPUNKNOWN)*ppvOut)->AddRef();
  245. hResult = NOERROR;
  246. }
  247. #ifdef POLICY_MMC_SNAPIN
  248. else if (IID_IComponentData == riid)
  249. {
  250. DBGPRINT((DM_COM, DL_MID, TEXT("Requested IID_IComponentData")));
  251. CSnapInCompData *psicd = new CSnapInCompData(g_hInstDll,
  252. CString(g_hInstDll, IDS_SNAPIN_NAME),
  253. CLSID_DiskQuotaUI);
  254. hResult = psicd->QueryInterface(riid, ppvOut);
  255. if (FAILED(hResult))
  256. delete psicd;
  257. }
  258. #endif // POLICY_MMC_SNAPIN
  259. else if (IID_IShellExtInit == riid)
  260. {
  261. DBGPRINT((DM_COM, DL_MID, TEXT("Requested IID_IShellExtInit")));
  262. ShellExtInit *pExtInit = new ShellExtInit;
  263. hResult = pExtInit->QueryInterface(IID_IShellExtInit, ppvOut);
  264. if (FAILED(hResult))
  265. delete pExtInit;
  266. }
  267. return hResult;
  268. }
  269. ULONG
  270. InstanceProxy::AddRef(
  271. VOID
  272. )
  273. {
  274. DBGTRACE((DM_COM, DL_MID, TEXT("InstanceProxy::AddRef")));
  275. ULONG ulReturn = m_cRef + 1;
  276. InterlockedIncrement(&m_cRef);
  277. return ulReturn;
  278. }
  279. ULONG
  280. InstanceProxy::Release(
  281. VOID
  282. )
  283. {
  284. DBGTRACE((DM_COM, DL_MID, TEXT("InstanceProxy::Release")));
  285. ULONG ulReturn = m_cRef - 1;
  286. if (InterlockedDecrement(&m_cRef) == 0)
  287. {
  288. delete this;
  289. ulReturn = 0;
  290. }
  291. return ulReturn;
  292. }