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.

129 lines
3.1 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: imminit.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This module implements IMM32 initialization
  7. *
  8. * History:
  9. * 03-Jan-1996 wkwok Created
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. // required for wow.obj in userrtl.lib
  14. extern ULONG_PTR gHighestUserAddress;
  15. BOOL ImmInitializeGlobals(HINSTANCE hmod)
  16. {
  17. SYSTEM_BASIC_INFORMATION SystemInformation;
  18. if (hmod) {
  19. /*
  20. * Remember IMM32.DLL's hmodule so we can grab resources from it later.
  21. */
  22. ghInst = hmod;
  23. }
  24. if (gfInitialized) {
  25. return TRUE;
  26. }
  27. if (!NT_SUCCESS(RtlInitializeCriticalSection(&gcsImeDpi))) {
  28. RIPMSG0(RIP_WARNING, "ImmInitializeGlobals: failed to initialize critical section at startup. Just bail.");
  29. return FALSE;
  30. }
  31. if (!NT_SUCCESS(NtQuerySystemInformation(SystemBasicInformation,
  32. &SystemInformation,
  33. sizeof(SystemInformation),
  34. NULL))) {
  35. RIPMSG0(RIP_WARNING, "ImmInitializeGlobals: failed to query system information. Just bail.");
  36. return FALSE;
  37. }
  38. gHighestUserAddress = SystemInformation.MaximumUserModeAddress;
  39. gfInitialized = TRUE;
  40. return TRUE;
  41. }
  42. BOOL ImmRegisterClient(
  43. IN PSHAREDINFO psiClient, HINSTANCE hmod)
  44. {
  45. gSharedInfo = *psiClient;
  46. gpsi = gSharedInfo.psi;
  47. /* Raid #97316
  48. * Dlls loaded earlier than imm32.dll could make
  49. * user32 call which calls back imm routines.
  50. * ImmRegisterClient() is called from User32's init routine,
  51. * so we can expect to reach here early enough.
  52. * We need to initialize globals as much as possible
  53. * here.
  54. */
  55. return ImmInitializeGlobals(hmod);
  56. }
  57. BOOL ImmDllInitialize(
  58. IN PVOID hmod,
  59. IN DWORD Reason,
  60. IN PCONTEXT pctx OPTIONAL)
  61. {
  62. UNREFERENCED_PARAMETER(pctx);
  63. switch ( Reason ) {
  64. case DLL_PROCESS_ATTACH:
  65. UserAssert(!gfInitialized || hmod == ghInst);
  66. if (!ImmInitializeGlobals(hmod))
  67. return FALSE;
  68. UserAssert(hmod != NULL);
  69. // Initialize USER32.DLL in case if USER32 has not bound itself to IMM32
  70. if (!User32InitializeImmEntryTable(IMM_MAGIC_CALLER_ID))
  71. return FALSE;
  72. break;
  73. case DLL_PROCESS_DETACH:
  74. if (gfInitialized) {
  75. RtlDeleteCriticalSection(&gcsImeDpi);
  76. }
  77. break;
  78. case DLL_THREAD_DETACH:
  79. if (IS_IME_ENABLED() && NtCurrentTebShared()->Win32ThreadInfo) {
  80. DestroyInputContext(
  81. (HIMC)NtUserGetThreadState(UserThreadStateDefaultInputContext),
  82. GetKeyboardLayout(0),
  83. TRUE);
  84. }
  85. break;
  86. default:
  87. break;
  88. }
  89. return TRUE;
  90. }
  91. PVOID UserRtlAllocMem(
  92. ULONG uBytes)
  93. {
  94. return LocalAlloc(LPTR, uBytes);
  95. }
  96. VOID UserRtlFreeMem(
  97. PVOID pMem)
  98. {
  99. LocalFree(pMem);
  100. }
  101. #if DBG
  102. DWORD GetRipComponent(
  103. VOID)
  104. {
  105. return RIP_IMM;
  106. }
  107. #endif