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.

268 lines
8.1 KiB

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