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.

189 lines
4.9 KiB

  1. /***************************************************************************
  2. * dll.c
  3. *
  4. * Standard DLL entry-point functions
  5. *
  6. ***************************************************************************/
  7. #include "priv.h"
  8. #include <ntverp.h>
  9. #include <isos.c>
  10. #define MLUI_INIT
  11. #include <mluisupp.h>
  12. HINSTANCE g_hinst = NULL;
  13. CRITICAL_SECTION g_csDll = {0};
  14. DWORD g_TpsTls = (UINT)-1;
  15. DWORD g_tlsThreadRef = (UINT)-1;
  16. DWORD g_tlsOtherThreadsRef = (UINT)-1;
  17. BOOL g_bDllTerminating = FALSE;
  18. #ifdef DEBUG
  19. //#define PROOFREAD_PARSES
  20. #endif
  21. #ifdef PROOFREAD_PARSES
  22. enum
  23. {
  24. PP_COMPARE,
  25. PP_ORIGINAL_ONLY,
  26. PP_NEW_ONLY
  27. };
  28. DWORD g_dwProofMode = PP_COMPARE;
  29. #endif // PROOFREAD_PARSES
  30. void TermPalette();
  31. void DeinitPUI();
  32. void FreeViewStatePropertyBagCache();
  33. void FreeDynamicLibraries();
  34. STDAPI_(void) FreeAllAccessSA();
  35. //
  36. // Table of all window classes we register so we can unregister them
  37. // at DLL unload.
  38. //
  39. // Since we are single-binary, we have to play it safe and do
  40. // this cleanup (needed only on NT, but harmless on Win95).
  41. //
  42. const LPCTSTR c_rgszClasses[] = {
  43. TEXT("WorkerA"), // util.cpp
  44. TEXT("WorkerW"), // util.cpp
  45. TEXT("WorkerW"), // util.cpp
  46. };
  47. //
  48. // Global DCs used during mirroring an Icon.
  49. //
  50. HDC g_hdc = NULL, g_hdcMask = NULL;
  51. BOOL g_bMirroredOS = FALSE;
  52. STDAPI_(void) InitShellKeys(BOOL fInit);
  53. #ifndef NO_ETW_TRACING
  54. ULONG UnRegisterTracing();
  55. #endif
  56. BOOL APIENTRY DllMain(IN HANDLE hDll, IN DWORD dwReason, IN LPVOID lpReserved)
  57. {
  58. switch(dwReason)
  59. {
  60. case DLL_PROCESS_ATTACH:
  61. DisableThreadLibraryCalls(hDll);
  62. #ifdef DEBUG
  63. CcshellGetDebugFlags();
  64. #endif
  65. InitializeCriticalSection(&g_csDll); // for later use
  66. g_hinst = hDll;
  67. MLLoadResources(g_hinst, TEXT("shlwaplc.dll"));
  68. InitStopWatchMode(); // See if perf mode is enabled
  69. // Check if we are running on a system that supports the mirroring APIs
  70. // i.e. (NT5 or Memphis/BiDi)
  71. //
  72. g_bMirroredOS = IS_MIRRORING_ENABLED();
  73. g_TpsTls = TlsAlloc();
  74. g_tlsThreadRef = TlsAlloc();
  75. g_tlsOtherThreadsRef = TlsAlloc();
  76. InitShellKeys(TRUE);
  77. #ifdef PROOFREAD_PARSES
  78. {
  79. DWORD dwSize = sizeof(g_dwProofMode);
  80. if (ERROR_SUCCESS != SHGetValue( HKEY_CURRENT_USER,
  81. TEXT("Software\\Microsoft\\Internet Explorer\\Main"),
  82. TEXT("Verify URLCombine"), NULL, &g_dwProofMode, &dwSize) ||
  83. (g_dwProofMode > PP_NEW_ONLY))
  84. {
  85. g_dwProofMode = PP_COMPARE;
  86. }
  87. }
  88. #endif
  89. break;
  90. case DLL_PROCESS_DETACH:
  91. g_bDllTerminating = TRUE;
  92. MLFreeResources(g_hinst);
  93. if (lpReserved == NULL)
  94. {
  95. DeinitPUI(); // free up plug ui resource hinstance dpa table
  96. FreeViewStatePropertyBagCache();
  97. }
  98. //
  99. // Icon mirroring stuff (see mirror.c)
  100. // Cleanup cached DCs. No need to synchronize the following section of
  101. // code since it is only called in DLL_PROCESS_DETACH which is
  102. // synchronized by the OS Loader.
  103. //
  104. if (g_bMirroredOS)
  105. {
  106. if (g_hdc)
  107. DeleteDC(g_hdc);
  108. if (g_hdcMask)
  109. DeleteDC(g_hdcMask);
  110. g_hdc = g_hdcMask = NULL;
  111. }
  112. FreeAllAccessSA();
  113. TermPalette();
  114. if (StopWatchMode()) {
  115. StopWatchFlush(); // Flush the performance timing data to disk
  116. #ifndef NO_ETW_TRACING
  117. // If any event tracing controls are enabled, this cleans them up.
  118. UnRegisterTracing();
  119. #endif
  120. }
  121. DeleteCriticalSection(&g_csDll);
  122. if (lpReserved == NULL)
  123. {
  124. SHTerminateThreadPool();
  125. SHUnregisterClasses(HINST_THISDLL, c_rgszClasses, ARRAYSIZE(c_rgszClasses));
  126. #ifdef I_WANT_WIN95_TO_CRASH
  127. // If you call FreeLibrary during PROCESS_ATTACH, Win95 will crash
  128. FreeDynamicLibraries();
  129. #endif
  130. }
  131. if (g_TpsTls != (UINT)-1)
  132. TlsFree(g_TpsTls);
  133. if (g_tlsThreadRef != (UINT)-1)
  134. TlsFree(g_tlsThreadRef);
  135. if (g_tlsOtherThreadsRef != (UINT)-1)
  136. TlsFree(g_tlsOtherThreadsRef);
  137. InitShellKeys(FALSE);
  138. break;
  139. case DLL_THREAD_ATTACH:
  140. case DLL_THREAD_DETACH:
  141. ASSERT(0); // We shouldn't get these because we called DisableThreadLibraryCalls().
  142. break;
  143. default:
  144. break;
  145. }
  146. return TRUE;
  147. }
  148. // DllGetVersion
  149. //
  150. // All we have to do is declare this puppy and CCDllGetVersion does the rest
  151. //
  152. DLLVER_SINGLEBINARY(VER_PRODUCTVERSION_DW, VER_PRODUCTBUILD_QFE);