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.

383 lines
10 KiB

  1. #include "pch.h" // PCH
  2. #pragma hdrstop
  3. #define INITGUIDS
  4. #include "dskquota.h"
  5. #include <gpedit.h> // Pick up IID_IGPEInformation
  6. #include <shfusion.h>
  7. #include "guidsp.h" // Private GUIDs.
  8. #include "factory.h" // Class factory declarations.
  9. #include "registry.h"
  10. //
  11. // Verify that build is UNICODE.
  12. //
  13. #if !defined(UNICODE)
  14. # error This module must be compiled UNICODE.
  15. #endif
  16. HINSTANCE g_hInstDll = NULL; // DLL instance handle.
  17. LONG g_cRefThisDll = 0; // DLL reference count.
  18. LONG g_cLockThisDll = 0; // DLL lock count.
  19. ///////////////////////////////////////////////////////////////////////////////
  20. /* Function: DllGetClassObject
  21. Description: Creates instance of DiskQuotaControlClassFactory.
  22. Arguments:
  23. rclsid - Reference to class ID that identifies the type of object that the
  24. class factory will be asked to create.
  25. riid - Reference to interface ID on the class factory object.
  26. ppvOut - Destination location for class factory object pointer after
  27. instantiation.
  28. Returns:
  29. NOERROR - Success.
  30. E_OUTOFMEMORY - Can't create class factory object.
  31. E_NOINTERFACE - Interface not supported.
  32. E_INVALIDARG - ppvOut arg is NULL.
  33. CLASS_E_CLASSNOTAVAILABLE - Class factory not available.
  34. Revision History:
  35. Date Description Programmer
  36. -------- --------------------------------------------------- ----------
  37. 05/22/96 Initial creation. BrianAu
  38. */
  39. ///////////////////////////////////////////////////////////////////////////////
  40. STDAPI
  41. DllGetClassObject(
  42. REFCLSID rclsid,
  43. REFIID riid,
  44. LPVOID *ppvOut
  45. )
  46. {
  47. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllGetClassObject")));
  48. HRESULT hResult = CLASS_E_CLASSNOTAVAILABLE;
  49. if (NULL == ppvOut)
  50. return E_INVALIDARG;
  51. *ppvOut = NULL;
  52. try
  53. {
  54. if (IsEqualIID(rclsid, CLSID_DiskQuotaUI))
  55. {
  56. DiskQuotaUIClassFactory *pClassFactory = NULL;
  57. pClassFactory = new DiskQuotaUIClassFactory;
  58. hResult = pClassFactory->QueryInterface(riid, ppvOut);
  59. if (FAILED(hResult))
  60. {
  61. delete pClassFactory;
  62. }
  63. }
  64. }
  65. catch(CAllocException& e)
  66. {
  67. hResult = E_OUTOFMEMORY;
  68. }
  69. return hResult;
  70. }
  71. ///////////////////////////////////////////////////////////////////////////////
  72. /* Function: DllCanUnloadNow
  73. Description: Called by OLE to determine if DLL can be unloaded.
  74. Arguments: None.
  75. Returns:
  76. S_FALSE - Can't unload. Ref count or lock count are > 0.
  77. S_OK - OK to unload. Ref count and lock count are 0.
  78. Revision History:
  79. Date Description Programmer
  80. -------- --------------------------------------------------- ----------
  81. 05/22/96 Initial creation. BrianAu
  82. */
  83. ///////////////////////////////////////////////////////////////////////////////
  84. STDAPI
  85. DllCanUnloadNow(
  86. VOID
  87. )
  88. {
  89. DBGPRINT((DM_COM, DL_HIGH, TEXT("DllCanUnloadNow (dskquoui.dll) RefCnt = %d LockCnt = %d"),
  90. g_cRefThisDll, g_cLockThisDll));
  91. #ifdef DEBUG_PROCESS_DETACH
  92. //
  93. // This code will force the DLL to be unloaded so that we can
  94. // test OnProcessDetach(). Otherwise, OLE will wait 10 minutes
  95. // after DllCanUnloadNow returns S_OK to call FreeLibrary.
  96. // Note however that the process will AV when OLE finally gets
  97. // around to freeing the library. Therefore, we don't leave
  98. // this code active in free or check builds; only private debug
  99. // builds. Must explicitly define DEBUG_PROCESS_DETACH.
  100. //
  101. if (0 == g_cRefThisDll && 0 == g_cLockThisDll)
  102. {
  103. HINSTANCE hMod;
  104. static INT iExeThisPath = 0;
  105. if (0 == iExeThisPath++)
  106. {
  107. hMod = LoadLibrary(TEXT("dskquota.dll"));
  108. if (NULL != hMod)
  109. {
  110. Assert(g_hInstDll == hMod);
  111. FreeLibrary(hMod);
  112. FreeLibrary(hMod);
  113. }
  114. }
  115. }
  116. #endif // DEBUG_PROCESS_DETACH
  117. return (0 == g_cRefThisDll && 0 == g_cLockThisDll) ? S_OK : S_FALSE;
  118. }
  119. ///////////////////////////////////////////////////////////////////////////////
  120. /* Function: DllRegisterServer
  121. Description: Create the necessary registry entries for dskquoui.dll
  122. to operate properly. This is typically called by REGSVR32.EXE.
  123. Arguments: None.
  124. Returns:
  125. S_OK - Succeeded.
  126. SELFREG_E_CLASS - Failed to create one of the registry entries.
  127. Revision History:
  128. Date Description Programmer
  129. -------- --------------------------------------------------- ----------
  130. 08/18/97 Initial creation. BrianAu
  131. */
  132. ///////////////////////////////////////////////////////////////////////////////
  133. HRESULT
  134. DllRegisterServer(
  135. VOID
  136. )
  137. {
  138. HRESULT hResult = CallRegInstall(g_hInstDll, "RegDll");
  139. if (FAILED(hResult))
  140. {
  141. hResult = SELFREG_E_CLASS;
  142. }
  143. return hResult;
  144. }
  145. ///////////////////////////////////////////////////////////////////////////////
  146. /* Function: DllUnregisterServer
  147. Description: Remove the necessary registry entries for dskquoui.dll.
  148. This is typically called by REGSVR32.EXE.
  149. Arguments: None.
  150. Returns:
  151. S_OK - Succeeded.
  152. SELFREG_E_CLASS - Failed to remove the CLSID entry.
  153. Revision History:
  154. Date Description Programmer
  155. -------- --------------------------------------------------- ----------
  156. 08/18/97 Initial creation. BrianAu
  157. */
  158. ///////////////////////////////////////////////////////////////////////////////
  159. HRESULT
  160. DllUnregisterServer(
  161. VOID
  162. )
  163. {
  164. HRESULT hResult = CallRegInstall(g_hInstDll, "UnregDll");
  165. if (FAILED(hResult))
  166. {
  167. hResult = SELFREG_E_CLASS;
  168. }
  169. return hResult;
  170. }
  171. ///////////////////////////////////////////////////////////////////////////////
  172. /* Function: OnProcessAttach
  173. Description: Handles all tasks associated with a process attaching to
  174. the DLL.
  175. Try to keep processing time to a minimum.
  176. Arguments:
  177. hInstDll - The DLL instance handle passed to DllMain.
  178. Returns:
  179. NO_ERROR - Success.
  180. E_FAIL - Something failed.
  181. Revision History:
  182. Date Description Programmer
  183. -------- --------------------------------------------------- ----------
  184. 08/09/96 Initial creation. BrianAu
  185. */
  186. ///////////////////////////////////////////////////////////////////////////////
  187. HRESULT
  188. OnProcessAttach(
  189. HINSTANCE hInstDll
  190. )
  191. {
  192. HRESULT hResult = NOERROR;
  193. //
  194. // Be specific - you want to use this dll's manifest (in resources at ID 1.)
  195. //
  196. SHFusionInitializeFromModuleID(hInstDll, 1);
  197. //
  198. // Start IceCAP profiling.
  199. //
  200. ICAP_START_ALL;
  201. #if DBG
  202. DBGMODULE(TEXT("DSKQUOUI")); // Name of module displayed with messages.
  203. RegKey key(HKEY_CURRENT_USER, REGSTR_KEY_DISKQUOTA);
  204. if (SUCCEEDED(key.Open(KEY_READ)))
  205. {
  206. DebugRegParams dp;
  207. if (SUCCEEDED(key.GetValue(REGSTR_VAL_DEBUGPARAMS, (LPBYTE)&dp, sizeof(dp))))
  208. {
  209. DBGPRINTMASK(dp.PrintMask);
  210. DBGPRINTLEVEL(dp.PrintLevel);
  211. DBGPRINTVERBOSE(dp.PrintVerbose);
  212. DBGTRACEMASK(dp.TraceMask);
  213. DBGTRACELEVEL(dp.TraceLevel);
  214. DBGTRACEVERBOSE(dp.TraceVerbose);
  215. DBGTRACEONEXIT(dp.TraceOnExit);
  216. }
  217. }
  218. #endif // DBG
  219. g_hInstDll = hInstDll;
  220. DisableThreadLibraryCalls(hInstDll);
  221. return hResult;
  222. }
  223. ///////////////////////////////////////////////////////////////////////////////
  224. /* Function: OnProcessDetach
  225. Description: Handles all tasks associated with a process detaching from
  226. the DLL.
  227. Arguments: None.
  228. Returns:
  229. NO_ERROR - Success.
  230. E_FAIL - Something failed.
  231. Revision History:
  232. Date Description Programmer
  233. -------- --------------------------------------------------- ----------
  234. 08/09/96 Initial creation. BrianAu
  235. */
  236. ///////////////////////////////////////////////////////////////////////////////
  237. HRESULT
  238. OnProcessDetach(
  239. VOID
  240. )
  241. {
  242. HRESULT hResult = NO_ERROR;
  243. SHFusionUninitialize();
  244. #ifdef DEBUG_PROCESS_DETACH
  245. LoadLibrary(TEXT("dskquoui.dll"));
  246. #endif
  247. //
  248. // Stop IceCAP profiling.
  249. //
  250. ICAP_STOP_ALL;
  251. return hResult;
  252. }
  253. ///////////////////////////////////////////////////////////////////////////////
  254. /* Function: DllMain
  255. Description: Main entry point for OLE component server.
  256. Arguments:
  257. hInstDll - Instance handle of DLL
  258. fdwReason - Reason DllMain is being called. Can be at Process attach/
  259. detach or Thread attach/detach.
  260. lpdwReserved - Reserved.
  261. Returns:
  262. TRUE - Successful initialization.
  263. FALSE - Failed initialization.
  264. Revision History:
  265. Date Description Programmer
  266. -------- --------------------------------------------------- ----------
  267. 05/22/96 Initial creation. BrianAu
  268. 08/09/96 Moved code associated with process attach and BrianAu
  269. detach out to separate functions.
  270. */
  271. ///////////////////////////////////////////////////////////////////////////////
  272. BOOL WINAPI
  273. DllMain(
  274. HINSTANCE hInstDll,
  275. DWORD fdwReason,
  276. LPVOID lpvReserved
  277. )
  278. {
  279. BOOL bResult = FALSE;
  280. switch(fdwReason)
  281. {
  282. case DLL_PROCESS_ATTACH:
  283. DBGPRINT((DM_COM, DL_HIGH, TEXT("DSKQUOUI - DLL_PROCESS_ATTACH")));
  284. bResult = SUCCEEDED(OnProcessAttach(hInstDll));
  285. break;
  286. case DLL_THREAD_ATTACH:
  287. case DLL_THREAD_DETACH:
  288. bResult = TRUE;
  289. break;
  290. case DLL_PROCESS_DETACH:
  291. DBGPRINT((DM_COM, DL_HIGH, TEXT("DSKQUOUI - DLL_PROCESS_DETACH")));
  292. bResult = SUCCEEDED(OnProcessDetach());
  293. break;
  294. }
  295. return bResult;
  296. }