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.

216 lines
6.4 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. //
  14. // Vij Vasu (VVasu) 29-AUG-2000
  15. // Modified this file to remove dependency on Shell API since they
  16. // may not be present on the OS that this DLL runs in.
  17. // Removed unnecessary functions for the same reason.
  18. //
  19. // Geoffrey Pease (GPease) 22-NOV-1999
  20. // Original version.
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include "Pch.h"
  24. //////////////////////////////////////////////////////////////////////////////
  25. // Macro Definitions
  26. //////////////////////////////////////////////////////////////////////////////
  27. // For tracing
  28. DEFINE_MODULE("CLUSCOMP")
  29. #include <DllSrc.cpp>
  30. #if 0
  31. //
  32. // DLL Globals
  33. //
  34. HINSTANCE g_hInstance = NULL;
  35. LONG g_cObjects = 0;
  36. LONG g_cLock = 0;
  37. WCHAR g_szDllFilename[ MAX_PATH ] = { 0 };
  38. LPVOID g_GlobalMemoryList = NULL; // Global memory tracking list
  39. #if !defined(NO_DLL_MAIN) || defined(DEBUG)
  40. //////////////////////////////////////////////////////////////////////////////
  41. //
  42. // BOOL
  43. // WINAPI
  44. // DLLMain(
  45. // HANDLE hInstIn,
  46. // ULONG ulReasonIn,
  47. // LPVOID lpReservedIn
  48. // )
  49. //
  50. // Description:
  51. // Dll entry point.
  52. //
  53. // Arguments:
  54. // hInstIn - DLL instance handle.
  55. // ulReasonIn - DLL reason code for entrance.
  56. // lpReservedIn - Not used.
  57. //
  58. //////////////////////////////////////////////////////////////////////////////
  59. BOOL WINAPI
  60. DllMain(
  61. HANDLE hInstIn,
  62. ULONG ulReasonIn,
  63. LPVOID // lpReservedIn
  64. )
  65. {
  66. //
  67. // KB: NO_THREAD_OPTIMIZATIONS gpease 19-OCT-1999
  68. //
  69. // By not defining this you can prvent the linker
  70. // from calling you DllEntry for every new thread.
  71. // This makes creating new thread significantly
  72. // faster if every DLL in a process does it.
  73. // Unfortunately, not all DLLs do this.
  74. //
  75. // In CHKed/DEBUG, we keep this on for memory
  76. // tracking.
  77. //
  78. #if defined( DEBUG )
  79. #define NO_THREAD_OPTIMIZATIONS
  80. #endif // DEBUG
  81. #if defined(NO_THREAD_OPTIMIZATIONS)
  82. switch( ulReasonIn )
  83. {
  84. case DLL_PROCESS_ATTACH:
  85. {
  86. TraceInitializeProcess( TRUE );
  87. TraceCreateMemoryList( g_GlobalMemoryList );
  88. #if defined( DEBUG )
  89. TraceFunc( "" );
  90. TraceMessage( TEXT(__FILE__),
  91. __LINE__,
  92. __MODULE__,
  93. mtfDLL,
  94. L"DLL: DLL_PROCESS_ATTACH - ThreadID = %#x",
  95. GetCurrentThreadId( )
  96. );
  97. FRETURN( TRUE );
  98. #endif // DEBUG
  99. g_hInstance = (HINSTANCE) hInstIn;
  100. GetModuleFileNameW( g_hInstance, g_szDllFilename, MAX_PATH );
  101. break;
  102. }
  103. case DLL_PROCESS_DETACH:
  104. {
  105. #if defined( DEBUG )
  106. TraceFunc( "" );
  107. TraceMessage( TEXT(__FILE__),
  108. __LINE__,
  109. __MODULE__,
  110. mtfDLL,
  111. L"DLL: DLL_PROCESS_DETACH - ThreadID = %#x [ g_cLock=%u, g_cObjects=%u ]",
  112. GetCurrentThreadId( ),
  113. g_cLock,
  114. g_cObjects
  115. );
  116. FRETURN( TRUE );
  117. #endif // DEBUG
  118. TraceTerminateMemoryList( g_GlobalMemoryList );
  119. TraceTerminateProcess();
  120. break;
  121. }
  122. case DLL_THREAD_ATTACH:
  123. {
  124. TraceInitializeThread( NULL );
  125. #if defined( DEBUG )
  126. TraceMessage( TEXT(__FILE__),
  127. __LINE__,
  128. __MODULE__,
  129. mtfDLL,
  130. L"The thread 0x%x has started.",
  131. GetCurrentThreadId( ) );
  132. TraceFunc( "" );
  133. TraceMessage( TEXT(__FILE__),
  134. __LINE__,
  135. __MODULE__,
  136. mtfDLL,
  137. L"DLL: DLL_THREAD_ATTACH - ThreadID = %#x [ g_cLock=%u, g_cObjects=%u ]",
  138. GetCurrentThreadId( ),
  139. g_cLock,
  140. g_cObjects
  141. );
  142. FRETURN( TRUE );
  143. #endif // DEBUG
  144. break;
  145. }
  146. case DLL_THREAD_DETACH:
  147. {
  148. #if defined( DEBUG )
  149. TraceFunc( "" );
  150. TraceMessage( TEXT(__FILE__),
  151. __LINE__,
  152. __MODULE__,
  153. mtfDLL,
  154. L"DLL: DLL_THREAD_DETACH - ThreadID = %#x [ g_cLock=%u, g_cObjects=%u ]",
  155. GetCurrentThreadId( ),
  156. g_cLock,
  157. g_cObjects
  158. );
  159. FRETURN( TRUE );
  160. #endif // DEBUG
  161. TraceThreadRundown( );;
  162. break;
  163. }
  164. default:
  165. {
  166. #if defined( DEBUG )
  167. TraceFunc( "" );
  168. TraceMessage( TEXT(__FILE__),
  169. __LINE__,
  170. __MODULE__,
  171. mtfDLL,
  172. L"DLL: UNKNOWN ENTRANCE REASON - ThreadID = %#x [ g_cLock=%u, g_cObjects=%u ]",
  173. GetCurrentThreadId( ),
  174. g_cLock,
  175. g_cObjects
  176. );
  177. FRETURN( TRUE );
  178. #endif // DEBUG
  179. break;
  180. }
  181. }
  182. return TRUE;
  183. #else // !NO_THREAD_OPTIMIZATIONS
  184. BOOL fResult;
  185. Assert( ulReasonIn == DLL_PROCESS_ATTACH || ulReasonIn == DLL_PROCESS_DETACH );
  186. #if defined(DEBUG)
  187. TraceInitializeProcess( TRUE );
  188. #endif // DEBUG
  189. g_hInstance = (HINSTANCE) hInstIn;
  190. GetModuleFileNameW( g_hInstance, g_szDllFilename, MAX_PATH );
  191. fResult = DisableThreadLibraryCalls( g_hInstance );
  192. AssertMsg( fResult, "*ERROR* DisableThreadLibraryCalls( ) failed." );
  193. return TRUE;
  194. #endif // NO_THREAD_OPTIMIZATIONS
  195. } //*** DllMain()
  196. #endif // !defined(NO_DLL_MAIN) && !defined(DEBUG)
  197. #endif