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.

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