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.

250 lines
5.0 KiB

  1. /*
  2. * init.cxx
  3. *
  4. *
  5. * Copyright (c) 1998 Microsoft Corporation
  6. *
  7. * PURPOSE: Initializes/deinitializes all required libraries
  8. * Designed to be included into a target DLL file.
  9. *
  10. *
  11. * OWNER: vivekj
  12. */
  13. // free functions
  14. BOOL
  15. CMMCFrame::s_fInitialized = FALSE;
  16. /* CMMCFrame::CMMCFrame
  17. *
  18. * PURPOSE: Constructor. Initializes the MMC frame class.
  19. *
  20. * PARAMETERS:
  21. * void:
  22. */
  23. CMMCFrame::CMMCFrame(void)
  24. {
  25. }
  26. /* CMMCFrame::~CMMCFrame
  27. *
  28. * PURPOSE: Destructor
  29. *
  30. * PARAMETERS: None
  31. *
  32. */
  33. CMMCFrame::~CMMCFrame()
  34. {
  35. }
  36. /* CMMCFrame::DeinitInstance
  37. *
  38. * PURPOSE: Deinitializes the particular loaded instance of the DLL.
  39. *
  40. * PARAMETERS:
  41. * void:
  42. *
  43. * RETURNS:
  44. * void
  45. */
  46. void
  47. CMMCFrame::DeinitInstance( void )
  48. {
  49. CBaseUIFrame::DeinitInstance();
  50. }
  51. /* CMMCFrame::ScInitApplication
  52. *
  53. * PURPOSE:
  54. *
  55. * PARAMETERS:
  56. * void:
  57. *
  58. * RETURNS:
  59. * SC
  60. */
  61. SC CMMCFrame::ScInitApplication( void )
  62. {
  63. SC sc = S_OK;
  64. sc = ScInitApplicationBaseMMC();
  65. if (sc)
  66. goto Error;
  67. Cleanup:
  68. return sc;
  69. Error:
  70. TraceError(_T("CMMCFrame::ScInitApplication"), sc);
  71. goto Cleanup;
  72. }
  73. //
  74. // Must uninitialize things that were initialized in
  75. // ScInitApplication.
  76. //
  77. void CMMCFrame::DeinitApplication(void)
  78. {
  79. }
  80. /* CMMCFrame::ScInitInstance
  81. *
  82. * PURPOSE:
  83. *
  84. * PARAMETERS:
  85. * void:
  86. *
  87. * RETURNS:
  88. * SC
  89. */
  90. SC CMMCFrame::ScInitInstance( void )
  91. {
  92. SC sc = S_OK;
  93. DWORD dwFlags = 0;
  94. sc = CBaseUIFrame::ScInitInstance();
  95. if (sc)
  96. goto Error;
  97. sc = ScInitInstanceBaseMMC();
  98. if (sc)
  99. goto Error;
  100. Cleanup:
  101. return sc;
  102. Error:
  103. TraceError(_T("CMMCFrame::ScInitInstance"), sc);
  104. goto Cleanup;
  105. }
  106. CBaseFrame * PframeCreate( void )
  107. {
  108. CMMCFrame * pframe;
  109. pframe = new CMMCFrame;
  110. return pframe;
  111. }
  112. /* CMMCFrame::Initialize
  113. *
  114. * PURPOSE: This version of Initialize is designed to be called from the DLL_PROCESS_ATTACH section
  115. * of DllMain. It does simple things like setting global static variables.
  116. *
  117. * PARAMETERS:
  118. * INSTANCE hinst: The handle to the running instance.
  119. * HINSTANCE hinstPrev: The handle to any previous instance.
  120. * CBaseFrame::PropSheetProviderType pspt: The type of property pages needed.
  121. * LPSTR:
  122. * int n:
  123. *
  124. * RETURNS:
  125. * void
  126. */
  127. void
  128. CMMCFrame::Initialize(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR, int n)
  129. {
  130. CBaseUIFrame::s_hinst = hinst;
  131. CBaseFrame::s_hinstPrev = hinstPrev;
  132. }
  133. /* CMMCFrame::Initialize()
  134. *
  135. * PURPOSE: Initializes the DLL. Note: This should be called by all DLL entry points
  136. * EXCEPT DLLMain, because it creates new threads, which DLLMain cannot do.
  137. * If it is called from DLLMain, the system will hang.
  138. *
  139. * PARAMETERS: None
  140. */
  141. void CMMCFrame::Initialize()
  142. {
  143. SC sc = S_OK;
  144. if(!s_fInitialized)
  145. {
  146. s_fInitialized = TRUE;
  147. CBaseFrame::s_pframe = PframeCreate();
  148. if (!CBaseUIFrame::Pframe())
  149. {
  150. sc = E_OUTOFMEMORY;
  151. goto Error;
  152. }
  153. if (!CBaseFrame::s_hinstPrev)
  154. {
  155. sc = CBaseUIFrame::Pframe()->ScInitApplication();
  156. if (sc)
  157. goto Error;
  158. }
  159. sc = CBaseUIFrame::Pframe()->ScInitInstance();
  160. if (sc)
  161. goto Error;
  162. }
  163. Cleanup:
  164. return;
  165. Error:
  166. TraceError(_T("CMMCFrame::Initialize"), sc);
  167. MMCErrorBox(sc);
  168. if (CBaseUIFrame::Pframe())
  169. {
  170. CBaseUIFrame::Pframe()->DeinitInstance();
  171. CBaseUIFrame::Pframe()->DeinitApplication();
  172. delete CBaseUIFrame::Pframe();
  173. }
  174. goto Cleanup;
  175. }
  176. /* CMMCFrame::Uninitialize
  177. *
  178. * PURPOSE: Uninitialized the DLL, freeing up any resources. This should be
  179. * called from the DLL_PROCESS_DETACH section of DllMain.
  180. *
  181. * PARAMETERS: None
  182. *
  183. * RETURNS:
  184. * void
  185. */
  186. void
  187. CMMCFrame::Uninitialize()
  188. {
  189. if(s_fInitialized) // only uninitialize once
  190. {
  191. if (CBaseUIFrame::Pframe())
  192. {
  193. CBaseUIFrame::Pframe()->DeinitInstance();
  194. CBaseUIFrame::Pframe()->DeinitApplication();
  195. delete CBaseUIFrame::Pframe();
  196. }
  197. }
  198. s_fInitialized = FALSE;
  199. }