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.

149 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. dllmain.cpp
  5. Abstract:
  6. This file implements the DLL MAIN.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "globals.h"
  13. #include "dimmex.h"
  14. #include "dimmwrp.h"
  15. #include "oldaimm.h"
  16. #include "tls.h"
  17. DECLARE_OSVER()
  18. //+---------------------------------------------------------------------------
  19. //
  20. // ProcessAttach
  21. //
  22. //----------------------------------------------------------------------------
  23. BOOL ProcessAttach(HINSTANCE hInstance)
  24. {
  25. CcshellGetDebugFlags();
  26. g_hInst = hInstance;
  27. if (!g_cs.Init())
  28. return FALSE;
  29. Dbg_MemInit(TEXT("MSIMTF"), NULL);
  30. InitOSVer();
  31. #ifdef OLD_AIMM_ENABLED
  32. //
  33. // Might be required by some library function, so let's initialize
  34. // it as the first thing.
  35. //
  36. TFInitLib_PrivateForCiceroOnly(Internal_CoCreateInstance);
  37. #endif // OLD_AIMM_ENABLED
  38. if (IsOldAImm())
  39. {
  40. return OldAImm_DllProcessAttach(hInstance);
  41. }
  42. else
  43. {
  44. TLS::Initialize();
  45. }
  46. return TRUE;
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // ProcessDettach
  51. //
  52. //----------------------------------------------------------------------------
  53. void ProcessDettach(HINSTANCE hInstance)
  54. {
  55. #ifdef OLD_AIMM_ENABLED
  56. TFUninitLib();
  57. #endif // OLD_AIMM_ENABLED
  58. if (! IsOldAImm())
  59. {
  60. UninitFilterList();
  61. UninitAimmAtom();
  62. }
  63. if (IsOldAImm())
  64. {
  65. OldAImm_DllProcessDetach();
  66. }
  67. else
  68. {
  69. TLS::DestroyTLS();
  70. TLS::Uninitialize();
  71. }
  72. Dbg_MemUninit();
  73. g_cs.Delete();
  74. }
  75. //+---------------------------------------------------------------------------
  76. //
  77. // DllMain
  78. //
  79. //----------------------------------------------------------------------------
  80. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pvReserved)
  81. {
  82. switch (dwReason)
  83. {
  84. case DLL_PROCESS_ATTACH:
  85. //
  86. // Now real DllEntry point is _DllMainCRTStartup.
  87. // _DllMainCRTStartup does not call our DllMain(DLL_PROCESS_DETACH)
  88. // if our DllMain(DLL_PROCESS_ATTACH) fails.
  89. // So we have to clean this up.
  90. //
  91. if (!ProcessAttach(hInstance))
  92. {
  93. ProcessDettach(hInstance);
  94. return FALSE;
  95. }
  96. break;
  97. case DLL_THREAD_ATTACH:
  98. if (IsOldAImm())
  99. {
  100. return OldAImm_DllThreadAttach();
  101. }
  102. break;
  103. case DLL_THREAD_DETACH:
  104. if (IsOldAImm())
  105. {
  106. OldAImm_DllThreadDetach();
  107. }
  108. else
  109. {
  110. TLS::DestroyTLS();
  111. }
  112. break;
  113. case DLL_PROCESS_DETACH:
  114. ProcessDettach(hInstance);
  115. break;
  116. }
  117. return TRUE;
  118. }