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.

121 lines
3.1 KiB

  1. //---------------------------------------------------------------------------
  2. // DllMain.cpp - Dll Entry point for UxTheme DLL
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "Utils.h"
  6. #include "sethook.h"
  7. #include "CacheList.h"
  8. #include "RenderList.h"
  9. #include "info.h"
  10. #include "themeldr.h"
  11. //---------------------------------------------------------------------------
  12. BOOL ThreadStartUp()
  13. {
  14. BOOL fInit = ThemeLibStartUp(TRUE);
  15. Log(LOG_TMSTARTUP, L"Thread startup");
  16. return fInit;
  17. }
  18. //---------------------------------------------------------------------------
  19. BOOL ThreadShutDown()
  20. {
  21. Log(LOG_TMSTARTUP, L"Thread shutdown");
  22. ThemeLibShutDown(TRUE);
  23. //---- destroy the thread-local object pool ----
  24. CCacheList *pList = GetTlsCacheList(FALSE);
  25. if (pList)
  26. {
  27. TlsSetValue(_tls_CacheListIndex, NULL);
  28. delete pList;
  29. }
  30. return TRUE;
  31. }
  32. //---------------------------------------------------------------------------
  33. BOOL ProcessStartUp(HINSTANCE hModule)
  34. {
  35. //---- don't init twice ----
  36. if (g_fUxthemeInitialized)
  37. {
  38. return TRUE;
  39. }
  40. g_hInst = hModule;
  41. _tls_CacheListIndex = TlsAlloc();
  42. if (_tls_CacheListIndex == (DWORD) -1)
  43. goto exit;
  44. if (!ThemeLibStartUp(FALSE))
  45. goto cleanup4;
  46. if (!GlobalsStartup())
  47. goto cleanup3;
  48. if (!ThemeHookStartup())
  49. goto cleanup2;
  50. // everything succeeded!
  51. Log(LOG_TMSTARTUP, L"Finished ProcessStartUp() (succeeded)");
  52. return TRUE;
  53. cleanup2:
  54. GlobalsShutdown();
  55. cleanup3:
  56. ThemeLibShutDown(FALSE);
  57. cleanup4:
  58. TlsFree(_tls_CacheListIndex);
  59. exit:
  60. // something failed
  61. Log(LOG_TMSTARTUP, L"Finished ProcessStartUp() (failure)");
  62. return FALSE;
  63. }
  64. //---------------------------------------------------------------------------
  65. BOOL ProcessShutDown()
  66. {
  67. //---- beware: in case of StartUp failure, all resources may not have been allocated ----
  68. Log(LOG_TMSTARTUP, L"Starting ProcessShutDown()");
  69. ThreadShutDown(); // not called by system on last thread
  70. //---- process shutdown ----
  71. ThemeLibShutDown(FALSE);
  72. ThemeHookShutdown();
  73. GlobalsShutdown();
  74. TlsFree(_tls_CacheListIndex);
  75. _tls_CacheListIndex = 0xffffffff;
  76. return TRUE;
  77. }
  78. //---------------------------------------------------------------------------
  79. BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  80. {
  81. BOOL fOk = TRUE;
  82. switch (ul_reason_for_call)
  83. {
  84. case DLL_PROCESS_ATTACH:
  85. fOk = ProcessStartUp(hModule);
  86. break;
  87. case DLL_THREAD_ATTACH:
  88. fOk = ThreadStartUp();
  89. break;
  90. case DLL_THREAD_DETACH:
  91. fOk = ThreadShutDown();
  92. break;
  93. case DLL_PROCESS_DETACH:
  94. fOk = ProcessShutDown();
  95. break;
  96. }
  97. return fOk;
  98. }
  99. //---------------------------------------------------------------------------