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.

117 lines
3.1 KiB

  1. #include "stdinc.h"
  2. #include "fusionmodule.h"
  3. #include "FusionHandle.h"
  4. extern CFusionModule _Module;
  5. BOOL CFusionModule::ModuleDllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID pvReserved)
  6. {
  7. UNUSED(pvReserved);
  8. BOOL fResult = TRUE;
  9. if (dwReason == DLL_PROCESS_ATTACH)
  10. {
  11. if ((m_dwEnumLocaleTLS = ::TlsAlloc()) == -1)
  12. {
  13. fResult = FALSE;
  14. goto Exit;
  15. }
  16. #if DBG
  17. if ((m_dwTraceContextTLS = ::TlsAlloc()) == -1)
  18. {
  19. CSxsPreserveLastError ple;
  20. VERIFY(::TlsFree(m_dwEnumLocaleTLS) != 0);
  21. ple.Restore();
  22. m_dwEnumLocaleTLS = 0;
  23. fResult = FALSE;
  24. goto Exit;
  25. }
  26. #endif
  27. m_hInstDLL = hInstDLL;
  28. }
  29. else if (dwReason == DLL_PROCESS_DETACH)
  30. {
  31. if (m_dwEnumLocaleTLS != 0)
  32. {
  33. ::TlsFree(m_dwEnumLocaleTLS);
  34. m_dwEnumLocaleTLS = 0;
  35. }
  36. #if DBG
  37. if (m_dwTraceContextTLS != 0)
  38. {
  39. ::TlsFree(m_dwTraceContextTLS);
  40. m_dwTraceContextTLS = 0;
  41. }
  42. #endif
  43. }
  44. fResult = TRUE;
  45. Exit:
  46. return fResult;
  47. }
  48. HRESULT CFusionModule::Initialize()
  49. {
  50. HRESULT hr = NOERROR;
  51. ASSERT(!m_fFusionModuleInitialized);
  52. if (m_fFusionModuleInitialized)
  53. {
  54. hr = E_UNEXPECTED;
  55. goto Exit;
  56. }
  57. hr = m_OleAut.Init();
  58. if (FAILED(hr))
  59. goto Exit;
  60. m_fFusionModuleInitialized = true;
  61. hr = NOERROR;
  62. Exit:
  63. return hr;
  64. }
  65. BOOL CFusionModule::EnumSystemLocalesExA(LOCALE_ENUMPROCEXA lpLocaleEnumProc, DWORD dwFlags, LPVOID pvContext)
  66. {
  67. ENUMSYSTEMLOCALESEXCONTEXTA ctx;
  68. ASSERT(m_dwEnumLocaleTLS != 0);
  69. ctx.pvContext = pvContext;
  70. ctx.lpLocaleEnumProc = lpLocaleEnumProc;
  71. BOOL fSucceeded = ::TlsSetValue(m_dwEnumLocaleTLS, &ctx);
  72. if (fSucceeded)
  73. fSucceeded = ::EnumSystemLocalesA(&CFusionModule::EnumLocalesProcA, dwFlags);
  74. return fSucceeded;
  75. }
  76. BOOL CFusionModule::EnumSystemLocalesExW(LOCALE_ENUMPROCEXW lpLocaleEnumProc, DWORD dwFlags, LPVOID pvContext)
  77. {
  78. ENUMSYSTEMLOCALESEXCONTEXTW ctx;
  79. ASSERT(m_dwEnumLocaleTLS != 0);
  80. ctx.pvContext = pvContext;
  81. ctx.lpLocaleEnumProc = lpLocaleEnumProc;
  82. BOOL fSucceeded = ::TlsSetValue(m_dwEnumLocaleTLS, &ctx);
  83. if (fSucceeded)
  84. fSucceeded = ::EnumSystemLocalesW(&CFusionModule::EnumLocalesProcW, dwFlags);
  85. return fSucceeded;
  86. }
  87. BOOL CFusionModule::EnumLocalesProcA(LPSTR pszLCID)
  88. {
  89. ASSERT(_Module.m_dwEnumLocaleTLS != 0);
  90. LPENUMSYSTEMLOCALESEXCONTEXTA pCtx = reinterpret_cast<LPENUMSYSTEMLOCALESEXCONTEXTA>(::TlsGetValue(_Module.m_dwEnumLocaleTLS));
  91. ASSERT(pCtx != NULL);
  92. if (pCtx == NULL)
  93. return FALSE;
  94. return (*(pCtx->lpLocaleEnumProc))(pszLCID, pCtx->pvContext);
  95. }
  96. BOOL CFusionModule::EnumLocalesProcW(LPWSTR pszLCID)
  97. {
  98. ASSERT(_Module.m_dwEnumLocaleTLS != 0);
  99. LPENUMSYSTEMLOCALESEXCONTEXTW pCtx = reinterpret_cast<LPENUMSYSTEMLOCALESEXCONTEXTW>(::TlsGetValue(_Module.m_dwEnumLocaleTLS));
  100. ASSERT(pCtx != NULL);
  101. if (pCtx == NULL)
  102. return FALSE;
  103. return (*(pCtx->lpLocaleEnumProc))(pszLCID, pCtx->pvContext);
  104. }