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.

140 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ForceAnsiWindowProc.cpp
  5. Abstract:
  6. Apps call GetWindowLongA() to get a window procedure and subsequently
  7. does not call CallWindowProc() with the value returned from
  8. GetWindowLongA(). This SHIM calls GetWindowLongW( ), which returns the
  9. window procedure.
  10. If the app wants a Dialog procedure, we pass back our function
  11. and subsequently call CallWindowProc() in our function. SetWindowLongA()
  12. is hooked to prevent the app from setting our function as a Dialog Proc.
  13. Notes:
  14. This is a general purpose SHIM
  15. History:
  16. 03/16/2000 prashkud Created
  17. 01/30/2001 prashkud Converted to a general SHIM
  18. --*/
  19. #include "precomp.h"
  20. IMPLEMENT_SHIM_BEGIN(ForceAnsiWindowProc)
  21. #include "ShimHookMacro.h"
  22. APIHOOK_ENUM_BEGIN
  23. APIHOOK_ENUM_ENTRY(SetWindowLongA)
  24. APIHOOK_ENUM_ENTRY(GetWindowLongA)
  25. APIHOOK_ENUM_END
  26. #define HANDLE_MASK 0xffff0000
  27. LONG g_lGetWindowLongRet = 0;
  28. LRESULT
  29. MyProcAddress(
  30. HWND hWnd,
  31. UINT uMsg,
  32. WPARAM wParam,
  33. LPARAM lParam
  34. )
  35. {
  36. return CallWindowProcA(
  37. (WNDPROC) g_lGetWindowLongRet,
  38. hWnd,
  39. uMsg,
  40. wParam,
  41. lParam
  42. );
  43. }
  44. LONG
  45. APIHOOK(SetWindowLongA)(
  46. HWND hwnd,
  47. int nIndex,
  48. LONG dwNewLong
  49. )
  50. {
  51. LONG lRet = 0;
  52. // If the address that is being set is my address, don't!
  53. if (dwNewLong == (LONG)MyProcAddress)
  54. {
  55. lRet = 0;
  56. }
  57. else
  58. {
  59. lRet = ORIGINAL_API(SetWindowLongA)(hwnd,nIndex,dwNewLong);
  60. }
  61. return lRet;
  62. }
  63. /*++
  64. This function intercepts GetWindowLong( ), checks the nIndex for GWL_WNDPROC
  65. and if it is,calls GetWindowLongW( ). Otherwise, it calls GetWindowLongA( )
  66. --*/
  67. LONG
  68. APIHOOK(GetWindowLongA)(
  69. HWND hwnd,
  70. int nIndex )
  71. {
  72. LONG lRet = 0;
  73. // Apply the modification only if the App wants a WindowProc.
  74. if ((nIndex == GWL_WNDPROC) ||
  75. (nIndex == DWL_DLGPROC))
  76. {
  77. if ((nIndex == GWL_WNDPROC))
  78. {
  79. lRet = GetWindowLongW(hwnd, nIndex);
  80. }
  81. else
  82. {
  83. g_lGetWindowLongRet = ORIGINAL_API(GetWindowLongA)(
  84. hwnd,
  85. nIndex
  86. );
  87. if ((g_lGetWindowLongRet & HANDLE_MASK) == HANDLE_MASK)
  88. {
  89. lRet = (LONG) MyProcAddress;
  90. }
  91. else
  92. {
  93. lRet = g_lGetWindowLongRet;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. lRet = ORIGINAL_API(GetWindowLongA)(hwnd, nIndex);
  100. }
  101. return lRet;
  102. }
  103. /*++
  104. Register hooked functions
  105. --*/
  106. HOOK_BEGIN
  107. APIHOOK_ENTRY(USER32.DLL, SetWindowLongA)
  108. APIHOOK_ENTRY(USER32.DLL, GetWindowLongA)
  109. HOOK_END
  110. IMPLEMENT_SHIM_END