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.

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