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.

265 lines
7.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Dll.cpp
  7. //
  8. // Description:
  9. // DLL services/entry points.
  10. //
  11. // Maintained By:
  12. // Geoff Pease (GPease) 18-OCT-1999
  13. // Vij Vasu (Vvasu) 25-JAN-2001
  14. //
  15. // Notes:
  16. // The file Mgmt\Inc\DllSrc.cpp is not included in this file
  17. // because the inclusion of that file requires that the library
  18. // Mgmt\ClusCfg\Common\$(O)\Common.lib be linked with this DLL. Also,
  19. // the header file Guids.h from Mgmt\ClusCfg\Inc will be needed.
  20. // (DllSrc.cpp requires CFactorySrc.cpp which requires CITrackerSrc.cpp
  21. // which requires InterfaceTableSrc.cpp which needs Guids.h)
  22. //
  23. // Since I didn't wan't to "reach across" to the ClusCfg directory (and
  24. // since this DLL does not need class factories, interface tracking, etc.)
  25. // ClusOCM has it's own Dll.cpp.
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28. //////////////////////////////////////////////////////////////////////////////
  29. // Include Files
  30. //////////////////////////////////////////////////////////////////////////////
  31. // Precompiled header for this DLL
  32. #include "pch.h"
  33. //////////////////////////////////////////////////////////////////////////////
  34. // Macro Definitions
  35. //////////////////////////////////////////////////////////////////////////////
  36. // For tracing
  37. DEFINE_MODULE("CLUSOCM")
  38. //////////////////////////////////////////////////////////////////////////////
  39. // Global Variables
  40. //////////////////////////////////////////////////////////////////////////////
  41. // Handle to the instance of this DLL.
  42. HINSTANCE g_hInstance = NULL;
  43. LPVOID g_GlobalMemoryList = NULL;
  44. // Name of the DLL
  45. WCHAR g_szDllFilename[ MAX_PATH ] = { 0 };
  46. #if !defined(NO_DLL_MAIN) || defined(ENTRY_PREFIX) || defined(DEBUG)
  47. //////////////////////////////////////////////////////////////////////////////
  48. //
  49. // __declspec( dllexport )
  50. // BOOL
  51. // WINAPI
  52. // DLLMain(
  53. // HANDLE hInstIn,
  54. // ULONG ulReasonIn,
  55. // LPVOID lpReservedIn
  56. // )
  57. //
  58. // Description:
  59. // Dll entry point.
  60. //
  61. // Arguments:
  62. // hInstIn - DLL instance handle.
  63. // ulReasonIn - DLL reason code for entrance.
  64. // lpReservedIn - Not used.
  65. //
  66. //////////////////////////////////////////////////////////////////////////////
  67. __declspec( dllexport ) BOOL WINAPI
  68. DllMain(
  69. HANDLE hInstIn,
  70. ULONG ulReasonIn,
  71. LPVOID // lpReservedIn
  72. )
  73. {
  74. BOOL fReturnValue = TRUE;
  75. //
  76. // KB: NO_THREAD_OPTIMIZATIONS gpease 19-OCT-1999
  77. //
  78. // By not defining this you can prvent the linker
  79. // from calling you DllEntry for every new thread.
  80. // This makes creating new thread significantly
  81. // faster if every DLL in a process does it.
  82. // Unfortunately, not all DLLs do this.
  83. //
  84. // In CHKed/DEBUG, we keep this on for memory
  85. // tracking.
  86. //
  87. #if defined( DEBUG )
  88. #define NO_THREAD_OPTIMIZATIONS
  89. #endif // DEBUG
  90. #if defined(NO_THREAD_OPTIMIZATIONS)
  91. switch( ulReasonIn )
  92. {
  93. case DLL_PROCESS_ATTACH:
  94. {
  95. #if defined(USE_WMI_TRACING)
  96. TraceInitializeProcess( g_rgTraceControlGuidList, ARRAYSIZE( g_rgTraceControlGuidList ), TRUE );
  97. #else
  98. TraceInitializeProcess( TRUE );
  99. #endif
  100. #if defined( DEBUG )
  101. TraceFunc( "" );
  102. TraceMessage( TEXT(__FILE__),
  103. __LINE__,
  104. __MODULE__,
  105. mtfDLL,
  106. TEXT("DLL: DLL_PROCESS_ATTACH - ThreadID = %#x"),
  107. GetCurrentThreadId( )
  108. );
  109. FRETURN( fReturnValue );
  110. #endif // DEBUG
  111. g_hInstance = (HINSTANCE) hInstIn;
  112. #if defined( ENTRY_PREFIX )
  113. hProxyDll = g_hInstance;
  114. #endif
  115. GetModuleFileName( g_hInstance, g_szDllFilename, MAX_PATH );
  116. //
  117. // Create a global memory list so that memory allocated by one
  118. // thread and handed to another can be tracked without causing
  119. // unnecessary trace messages.
  120. //
  121. TraceCreateMemoryList( g_GlobalMemoryList );
  122. } // case: DLL_PROCESS_ATTACH
  123. break;
  124. case DLL_PROCESS_DETACH:
  125. {
  126. #if defined( DEBUG )
  127. TraceFunc( "" );
  128. TraceMessage( TEXT(__FILE__),
  129. __LINE__,
  130. __MODULE__,
  131. mtfDLL,
  132. TEXT("DLL: DLL_PROCESS_DETACH - ThreadID = %#x"),
  133. GetCurrentThreadId( )
  134. );
  135. FRETURN( fReturnValue );
  136. #endif // DEBUG
  137. //
  138. // Cleanup the global memory list used to track memory allocated
  139. // in one thread and then handed to another.
  140. //
  141. TraceTerminateMemoryList( g_GlobalMemoryList );
  142. #if defined(USE_WMI_TRACING)
  143. TraceTerminateProcess( g_rgTraceControlGuidList, ARRAYSIZE( g_rgTraceControlGuidList ) );
  144. #else
  145. TraceTerminateProcess();
  146. #endif
  147. } // case: DLL_PROCESS_DETACH
  148. break;
  149. case DLL_THREAD_ATTACH:
  150. {
  151. TraceInitializeThread( NULL );
  152. #if defined( DEBUG )
  153. TraceMessage( TEXT(__FILE__),
  154. __LINE__,
  155. __MODULE__,
  156. mtfDLL,
  157. TEXT("The thread %#x has started."),
  158. GetCurrentThreadId( ) );
  159. TraceFunc( "" );
  160. TraceMessage( TEXT(__FILE__),
  161. __LINE__,
  162. __MODULE__,
  163. mtfDLL,
  164. TEXT("DLL: DLL_THREAD_ATTACH - ThreadID = %#x"),
  165. GetCurrentThreadId( )
  166. );
  167. FRETURN( fReturnValue );
  168. #endif // DEBUG
  169. } // case: DLL_THREAD_ATTACH
  170. break;
  171. case DLL_THREAD_DETACH:
  172. {
  173. #if defined( DEBUG )
  174. TraceFunc( "" );
  175. TraceMessage( TEXT(__FILE__),
  176. __LINE__,
  177. __MODULE__,
  178. mtfDLL,
  179. TEXT("DLL: DLL_THREAD_DETACH - ThreadID = %#x"),
  180. GetCurrentThreadId( )
  181. );
  182. FRETURN( fReturnValue );
  183. #endif // DEBUG
  184. TraceThreadRundown( );
  185. } // case: DLL_THREAD_DETACH
  186. break;
  187. default:
  188. {
  189. #if defined( DEBUG )
  190. TraceFunc( "" );
  191. TraceMessage( TEXT(__FILE__),
  192. __LINE__,
  193. __MODULE__,
  194. mtfDLL,
  195. TEXT("DLL: UNKNOWN ENTRANCE REASON - ThreadID = %#x"),
  196. GetCurrentThreadId( )
  197. );
  198. FRETURN( fReturnValue );
  199. #endif // DEBUG
  200. } // case: default
  201. break;
  202. }
  203. return fReturnValue;
  204. #else // !NO_THREAD_OPTIMIZATIONS
  205. Assert( ulReasonIn == DLL_PROCESS_ATTACH || ulReasonIn == DLL_PROCESS_DETACH );
  206. #if defined(DEBUG)
  207. #if defined(USE_WMI_TRACING)
  208. TraceInitializeProcess( g_rgTraceControlGuidList,
  209. ARRAYSIZE( g_rgTraceControlGuidList )
  210. );
  211. #else
  212. TraceInitializeProcess();
  213. #endif
  214. #endif // DEBUG
  215. g_hInstance = (HINSTANCE) hInstIn;
  216. #if defined( ENTRY_PREFIX )
  217. hProxyDll = g_hInstance;
  218. #endif
  219. GetModuleFileName( g_hInstance, g_szDllFilename, MAX_PATH );
  220. fReturnValue = DisableThreadLibraryCalls( g_hInstance );
  221. AssertMsg( fReturnValue, "*ERROR* DisableThreadLibraryCalls( ) failed." );
  222. return fReturnValue;
  223. #endif // NO_THREAD_OPTIMIZATIONS
  224. } //*** DllMain()
  225. #endif // !defined(NO_DLL_MAIN) && !defined(ENTRY_PREFIX) && !defined(DEBUG)