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.

231 lines
5.9 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: ShellServicesExports.cpp
  3. //
  4. // Copyright (c) 2001, Microsoft Corporation
  5. //
  6. // This file contains functions that exported from shsvcs.dll.
  7. //
  8. // History: 2001-01-02 vtan created
  9. // --------------------------------------------------------------------------
  10. #include "StandardHeader.h"
  11. #include "ServerAPI.h"
  12. #include "BAMService.h"
  13. #include "HDService.h"
  14. #include "ThemeService.h"
  15. HINSTANCE g_hInstance = NULL;
  16. STDAPI_(BOOL) _ProcessAttach()
  17. {
  18. BOOL f = NT_SUCCESS(CServerAPI::StaticInitialize());
  19. if (!f)
  20. goto cleanup;
  21. f = CThemeService::Main(DLL_PROCESS_ATTACH);
  22. if (!f)
  23. goto cleanup1;
  24. f = CBAMService::Main(DLL_PROCESS_ATTACH);
  25. if (!f)
  26. goto cleanup2;
  27. f = CHDService::Main(DLL_PROCESS_ATTACH);
  28. if (!f)
  29. goto cleanup3;
  30. // success!
  31. goto cleanup;
  32. cleanup3:
  33. CBAMService::Main(DLL_PROCESS_DETACH);
  34. cleanup2:
  35. CThemeService::Main(DLL_PROCESS_DETACH);
  36. cleanup1:
  37. CServerAPI::StaticTerminate();
  38. cleanup:
  39. return f;
  40. }
  41. // --------------------------------------------------------------------------
  42. // ::DllMain
  43. //
  44. // Arguments: See the platform SDK under DllMain.
  45. //
  46. // Returns: See the platform SDK under DllMain.
  47. //
  48. // Purpose: Performs initialization and clean up on process attach and
  49. // detach. Not interested in anything else.
  50. //
  51. // History: 2001-01-02 vtan created
  52. // --------------------------------------------------------------------------
  53. EXTERN_C BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
  54. {
  55. UNREFERENCED_PARAMETER(lpvReserved);
  56. BOOL f;
  57. switch (fdwReason)
  58. {
  59. case DLL_PROCESS_ATTACH:
  60. g_hInstance = hInstance;
  61. #ifdef DEBUG
  62. __try
  63. {
  64. #endif // DEBUG
  65. f = _ProcessAttach();
  66. #ifdef DEBUG
  67. }
  68. __except(EXCEPTION_EXECUTE_HANDLER)
  69. {
  70. f = FALSE;
  71. OutputDebugString(TEXT("_ProcessAttach threw an unhandled exception! This should NOT happen \n"));
  72. DebugBreak();
  73. }
  74. #endif // DEBUG
  75. break;
  76. case DLL_PROCESS_DETACH:
  77. CHDService::Main(fdwReason);
  78. CBAMService::Main(fdwReason);
  79. CThemeService::Main(fdwReason);
  80. TSTATUS(CServerAPI::StaticTerminate());
  81. f = TRUE;
  82. break;
  83. default:
  84. f = TRUE;
  85. break;
  86. }
  87. return f;
  88. }
  89. // --------------------------------------------------------------------------
  90. // ::DllInstall
  91. //
  92. // Arguments: <none>
  93. //
  94. // Returns: HRESULT
  95. //
  96. // Purpose:
  97. //
  98. // History: 2001-01-02 vtan created
  99. // --------------------------------------------------------------------------
  100. HRESULT WINAPI DllInstall (BOOL fInstall, LPCWSTR pszCmdLine)
  101. {
  102. return(CHDService::Install(fInstall, pszCmdLine));
  103. }
  104. // --------------------------------------------------------------------------
  105. // ::DllRegisterServer
  106. //
  107. // Arguments: <none>
  108. //
  109. // Returns: HRESULT
  110. //
  111. // Purpose: Register entry point to allow any service to install itself
  112. // into the registry.
  113. //
  114. // History: 2001-01-02 vtan created
  115. // --------------------------------------------------------------------------
  116. HRESULT WINAPI DllRegisterServer (void)
  117. {
  118. HRESULT hr;
  119. NTSTATUS status1, status2;
  120. status1 = CThemeService::RegisterServer();
  121. status2 = CBAMService::RegisterServer();
  122. hr = CHDService::RegisterServer();
  123. if (!NT_SUCCESS(status1))
  124. {
  125. hr = HRESULT_FROM_NT(status1);
  126. }
  127. else if (!NT_SUCCESS(status2))
  128. {
  129. hr = HRESULT_FROM_NT(status2);
  130. }
  131. return(hr);
  132. }
  133. // --------------------------------------------------------------------------
  134. // ::DllUnregisterServer
  135. //
  136. // Arguments: <none>
  137. //
  138. // Returns: HRESULT
  139. //
  140. // Purpose: Unregister entry point to allow any service to uninstall
  141. // itself from the registry.
  142. //
  143. // History: 2001-01-02 vtan created
  144. // --------------------------------------------------------------------------
  145. HRESULT WINAPI DllUnregisterServer (void)
  146. {
  147. HRESULT hr;
  148. NTSTATUS status1, status2;
  149. hr = CHDService::UnregisterServer();
  150. status2 = CBAMService::UnregisterServer();
  151. status1 = CThemeService::UnregisterServer();
  152. if (!NT_SUCCESS(status1))
  153. {
  154. hr = HRESULT_FROM_NT(status1);
  155. }
  156. else if (!NT_SUCCESS(status2))
  157. {
  158. hr = HRESULT_FROM_NT(status2);
  159. }
  160. return(hr);
  161. }
  162. // --------------------------------------------------------------------------
  163. // ::DllCanUnloadNow
  164. //
  165. // Arguments: See the platform SDK under DllMain.
  166. //
  167. // Returns: See the platform SDK under DllMain.
  168. //
  169. // Purpose: Returns whether the DLL can unload because there are no
  170. // outstanding COM object references.
  171. //
  172. // History: 2001-01-02 vtan created
  173. // --------------------------------------------------------------------------
  174. HRESULT WINAPI DllCanUnloadNow (void)
  175. {
  176. return(CHDService::CanUnloadNow());
  177. }
  178. // --------------------------------------------------------------------------
  179. // ::DllGetClassObject
  180. //
  181. // Arguments: See the platform SDK under DllMain.
  182. //
  183. // Returns: See the platform SDK under DllMain.
  184. //
  185. // Purpose: Returns a constructed COM object of the specified class.
  186. //
  187. // History: 2001-01-02 vtan created
  188. // --------------------------------------------------------------------------
  189. HRESULT WINAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, void** ppv)
  190. {
  191. return(CHDService::GetClassObject(rclsid, riid, ppv));
  192. }