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.

275 lines
7.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. afpmgr.cxx
  7. This module contains the "LibMain" function.
  8. FILE HISTORY:
  9. NarenG 1-Oct-1991 Converted srvmgr.cpl to afpmgr.cpl
  10. */
  11. #define INCL_NET
  12. #define INCL_NETLIB
  13. #define INCL_NETSERVICE
  14. #define INCL_WINDOWS
  15. #define INCL_WINDOWS_GDI
  16. #define INCL_NETERRORS
  17. #define INCL_DOSERRORS
  18. #include <lmui.hxx>
  19. #if defined(DEBUG)
  20. static const CHAR szFileName[] = __FILE__;
  21. #define _FILENAME_DEFINED_ONCE szFileName
  22. #endif
  23. #include <uiassert.hxx>
  24. #include <uitrace.hxx>
  25. #define INCL_BLT_WINDOW
  26. #define INCL_BLT_DIALOG
  27. #define INCL_BLT_CONTROL
  28. #define INCL_BLT_CLIENT
  29. #define INCL_BLT_MSGPOPUP
  30. #define INCL_BLT_EVENT
  31. #define INCL_BLT_MISC
  32. #define INCL_BLT_TIMER
  33. #define INCL_BLT_CC
  34. #include <blt.hxx>
  35. #include <dbgstr.hxx>
  36. extern "C"
  37. {
  38. #include <afpmgr.h>
  39. //
  40. // DLL load/unload entry point.
  41. //
  42. BOOL FAR PASCAL AfpMgrDllInitialize( HINSTANCE hInstance,
  43. DWORD nReason,
  44. LPVOID pReserved );
  45. //
  46. // Globals.
  47. //
  48. HINSTANCE _hInstance = NULL;
  49. } // extern "C"
  50. /*******************************************************************
  51. NAME: InitializeAfpMgr
  52. SYNOPSIS: Called during processing of DLL_PROCESS_ATTACH notification to
  53. initialize the DLL.
  54. ENTRY:
  55. RETURNS: BOOL - TRUE = AfpMgr should be installed.
  56. FALSE = AfpMgr cannot be installed.
  57. HISTORY:
  58. NarenG 1-Oct-1992 Stole from original.
  59. ********************************************************************/
  60. BOOL InitializeAfpMgr( VOID )
  61. {
  62. //
  63. // Initialize all of the NetUI goodies.
  64. //
  65. APIERR err = BLT::Init( _hInstance,
  66. CID_AFPMGR_BASE, CID_AFPMGR_LAST,
  67. IDS_AFPMGR_BASE, IDS_AFPMGR_LAST );
  68. if( err == NERR_Success )
  69. {
  70. err = BLT_MASTER_TIMER::Init();
  71. if( err != NERR_Success )
  72. {
  73. //
  74. // BLT initialized OK, but BLT_MASTER_TIMER
  75. // failed. So, before we bag-out, we must
  76. // deinitialize BLT.
  77. //
  78. BLT::Term( _hInstance );
  79. }
  80. }
  81. if( err == NERR_Success )
  82. {
  83. err = BLT::RegisterHelpFile( _hInstance,
  84. IDS_AFPMGR_HELPFILENAME,
  85. HC_UI_AFPMGR_BASE,
  86. HC_UI_AFPMGR_LAST );
  87. if( err != NERR_Success )
  88. {
  89. //
  90. // This is the only place where we can safely
  91. // invoke MsgPopup, since we *know* that all of
  92. // the BLT goodies were initialized properly.
  93. //
  94. // ::MsgPopup( hWnd, err );
  95. }
  96. }
  97. return err == NERR_Success;
  98. } // InitializeAfpMgr
  99. /*******************************************************************
  100. NAME: TerminateAfpMgr
  101. SYNOPSIS: Called during processing of DLL_PROCESS_DETACH notification to
  102. terminate the AfpMgr.
  103. ENTRY: hWnd - Window handle of parent window.
  104. HISTORY:
  105. NarenG 1-Oct-1992 Stole from original.
  106. ********************************************************************/
  107. VOID TerminateAfpMgr( VOID )
  108. {
  109. //
  110. // Kill the NetUI goodies.
  111. //
  112. BLT_MASTER_TIMER::Term();
  113. BLT::Term( _hInstance );
  114. } // TerminateAfpMgr
  115. /*******************************************************************
  116. NAME: AfpMgrDllInitialize
  117. SYNOPSIS: This DLL entry point is called when processes & threads
  118. are initialized and terminated, or upon calls to
  119. LoadLibrary() and FreeLibrary().
  120. ENTRY: hInstance - A handle to the DLL.
  121. nReason - Indicates why the DLL entry
  122. point is being called.
  123. pReserved - Reserved.
  124. RETURNS: BOOL - TRUE = DLL init was successful.
  125. FALSE = DLL init failed.
  126. NOTES: The return value is only relevant during processing of
  127. DLL_PROCESS_ATTACH notifications.
  128. HISTORY:
  129. NarenG 1-Oct-1992 Stole from original.
  130. ********************************************************************/
  131. BOOL FAR PASCAL AfpMgrDllInitialize( HINSTANCE hInstance,
  132. DWORD nReason,
  133. LPVOID pReserved )
  134. {
  135. BOOL fResult = TRUE;
  136. UNREFERENCED( pReserved );
  137. switch( nReason )
  138. {
  139. case DLL_PROCESS_ATTACH:
  140. //
  141. // This notification indicates that the DLL is attaching to
  142. // the address space of the current process. This is either
  143. // the result of the process starting up, or after a call to
  144. // LoadLibrary(). The DLL should us this as a hook to
  145. // initialize any instance data or to allocate a TLS index.
  146. //
  147. // This call is made in the context of the thread that
  148. // caused the process address space to change.
  149. //
  150. _hInstance = hInstance;
  151. fResult = InitializeAfpMgr();
  152. break;
  153. case DLL_PROCESS_DETACH:
  154. //
  155. // This notification indicates that the calling process is
  156. // detaching the DLL from its address space. This is either
  157. // due to a clean process exit or from a FreeLibrary() call.
  158. // The DLL should use this opportunity to return any TLS
  159. // indexes allocated and to free any thread local data.
  160. //
  161. // Note that this notification is posted only once per
  162. // process. Individual threads do not invoke the
  163. // DLL_THREAD_DETACH notification.
  164. //
  165. TerminateAfpMgr();
  166. _hInstance = NULL;
  167. break;
  168. case DLL_THREAD_ATTACH:
  169. //
  170. // This notfication indicates that a new thread is being
  171. // created in the current process. All DLLs attached to
  172. // the process at the time the thread starts will be
  173. // notified. The DLL should use this opportunity to
  174. // initialize a TLS slot for the thread.
  175. //
  176. // Note that the thread that posts the DLL_PROCESS_ATTACH
  177. // notification will not post a DLL_THREAD_ATTACH.
  178. //
  179. // Note also that after a DLL is loaded with LoadLibrary,
  180. // only threads created after the DLL is loaded will
  181. // post this notification.
  182. //
  183. break;
  184. case DLL_THREAD_DETACH:
  185. //
  186. // This notification indicates that a thread is exiting
  187. // cleanly. The DLL should use this opportunity to
  188. // free any data stored in TLS indices.
  189. //
  190. break;
  191. default:
  192. //
  193. // Who knows? Just ignore it.
  194. //
  195. break;
  196. }
  197. return fResult;
  198. } // AfpMgrDllInitialize