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.

351 lines
9.7 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. return (0 == g_cRefThisDll && 0 == g_cLockThisDll) ? S_OK : S_FALSE;
  92. }
  93. ///////////////////////////////////////////////////////////////////////////////
  94. /* Function: DllRegisterServer
  95. Description: Create the necessary registry entries for dskquoui.dll
  96. to operate properly. This is typically called by REGSVR32.EXE.
  97. Arguments: None.
  98. Returns:
  99. S_OK - Succeeded.
  100. SELFREG_E_CLASS - Failed to create one of the registry entries.
  101. Revision History:
  102. Date Description Programmer
  103. -------- --------------------------------------------------- ----------
  104. 08/18/97 Initial creation. BrianAu
  105. */
  106. ///////////////////////////////////////////////////////////////////////////////
  107. HRESULT
  108. DllRegisterServer(
  109. VOID
  110. )
  111. {
  112. HRESULT hResult = CallRegInstall(g_hInstDll, "RegDll");
  113. if (FAILED(hResult))
  114. {
  115. hResult = SELFREG_E_CLASS;
  116. }
  117. return hResult;
  118. }
  119. ///////////////////////////////////////////////////////////////////////////////
  120. /* Function: DllUnregisterServer
  121. Description: Remove the necessary registry entries for dskquoui.dll.
  122. This is typically called by REGSVR32.EXE.
  123. Arguments: None.
  124. Returns:
  125. S_OK - Succeeded.
  126. SELFREG_E_CLASS - Failed to remove the CLSID entry.
  127. Revision History:
  128. Date Description Programmer
  129. -------- --------------------------------------------------- ----------
  130. 08/18/97 Initial creation. BrianAu
  131. */
  132. ///////////////////////////////////////////////////////////////////////////////
  133. HRESULT
  134. DllUnregisterServer(
  135. VOID
  136. )
  137. {
  138. HRESULT hResult = CallRegInstall(g_hInstDll, "UnregDll");
  139. if (FAILED(hResult))
  140. {
  141. hResult = SELFREG_E_CLASS;
  142. }
  143. return hResult;
  144. }
  145. ///////////////////////////////////////////////////////////////////////////////
  146. /* Function: OnProcessAttach
  147. Description: Handles all tasks associated with a process attaching to
  148. the DLL.
  149. Try to keep processing time to a minimum.
  150. Arguments:
  151. hInstDll - The DLL instance handle passed to DllMain.
  152. Returns:
  153. NO_ERROR - Success.
  154. E_FAIL - Something failed.
  155. Revision History:
  156. Date Description Programmer
  157. -------- --------------------------------------------------- ----------
  158. 08/09/96 Initial creation. BrianAu
  159. */
  160. ///////////////////////////////////////////////////////////////////////////////
  161. HRESULT
  162. OnProcessAttach(
  163. HINSTANCE hInstDll
  164. )
  165. {
  166. HRESULT hResult = NOERROR;
  167. //
  168. // Be specific - you want to use this dll's manifest (in resources at ID 1.)
  169. //
  170. SHFusionInitializeFromModuleID(hInstDll, 1);
  171. //
  172. // Start IceCAP profiling.
  173. //
  174. ICAP_START_ALL;
  175. #if DBG
  176. DBGMODULE(TEXT("DSKQUOUI")); // Name of module displayed with messages.
  177. RegKey key(HKEY_CURRENT_USER, REGSTR_KEY_DISKQUOTA);
  178. if (SUCCEEDED(key.Open(KEY_READ)))
  179. {
  180. DebugRegParams dp;
  181. if (SUCCEEDED(key.GetValue(REGSTR_VAL_DEBUGPARAMS, (LPBYTE)&dp, sizeof(dp))))
  182. {
  183. DBGPRINTMASK(dp.PrintMask);
  184. DBGPRINTLEVEL(dp.PrintLevel);
  185. DBGPRINTVERBOSE(dp.PrintVerbose);
  186. DBGTRACEMASK(dp.TraceMask);
  187. DBGTRACELEVEL(dp.TraceLevel);
  188. DBGTRACEVERBOSE(dp.TraceVerbose);
  189. DBGTRACEONEXIT(dp.TraceOnExit);
  190. }
  191. }
  192. #endif // DBG
  193. g_hInstDll = hInstDll;
  194. DisableThreadLibraryCalls(hInstDll);
  195. return hResult;
  196. }
  197. ///////////////////////////////////////////////////////////////////////////////
  198. /* Function: OnProcessDetach
  199. Description: Handles all tasks associated with a process detaching from
  200. the DLL.
  201. Arguments: None.
  202. Returns:
  203. NO_ERROR - Success.
  204. E_FAIL - Something failed.
  205. Revision History:
  206. Date Description Programmer
  207. -------- --------------------------------------------------- ----------
  208. 08/09/96 Initial creation. BrianAu
  209. */
  210. ///////////////////////////////////////////////////////////////////////////////
  211. HRESULT
  212. OnProcessDetach(
  213. VOID
  214. )
  215. {
  216. HRESULT hResult = NO_ERROR;
  217. SHFusionUninitialize();
  218. //
  219. // Stop IceCAP profiling.
  220. //
  221. ICAP_STOP_ALL;
  222. return hResult;
  223. }
  224. ///////////////////////////////////////////////////////////////////////////////
  225. /* Function: DllMain
  226. Description: Main entry point for OLE component server.
  227. Arguments:
  228. hInstDll - Instance handle of DLL
  229. fdwReason - Reason DllMain is being called. Can be at Process attach/
  230. detach or Thread attach/detach.
  231. lpdwReserved - Reserved.
  232. Returns:
  233. TRUE - Successful initialization.
  234. FALSE - Failed initialization.
  235. Revision History:
  236. Date Description Programmer
  237. -------- --------------------------------------------------- ----------
  238. 05/22/96 Initial creation. BrianAu
  239. 08/09/96 Moved code associated with process attach and BrianAu
  240. detach out to separate functions.
  241. */
  242. ///////////////////////////////////////////////////////////////////////////////
  243. BOOL WINAPI
  244. DllMain(
  245. HINSTANCE hInstDll,
  246. DWORD fdwReason,
  247. LPVOID lpvReserved
  248. )
  249. {
  250. BOOL bResult = FALSE;
  251. switch(fdwReason)
  252. {
  253. case DLL_PROCESS_ATTACH:
  254. DBGPRINT((DM_COM, DL_HIGH, TEXT("DSKQUOUI - DLL_PROCESS_ATTACH")));
  255. bResult = SUCCEEDED(OnProcessAttach(hInstDll));
  256. break;
  257. case DLL_THREAD_ATTACH:
  258. case DLL_THREAD_DETACH:
  259. bResult = TRUE;
  260. break;
  261. case DLL_PROCESS_DETACH:
  262. DBGPRINT((DM_COM, DL_HIGH, TEXT("DSKQUOUI - DLL_PROCESS_DETACH")));
  263. bResult = SUCCEEDED(OnProcessDetach());
  264. break;
  265. }
  266. return bResult;
  267. }