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.

156 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. NBALive.cpp
  5. Abstract:
  6. On Win9x, SetWindowText used to pass the pointer directly to the window
  7. proc in a WM_SETTEXT message. However, on NT, the string goes through the
  8. standard message workers and get's converted to unicode etc. When it does
  9. get to the window proc, it's not the original pointer.
  10. NBA Live 99 depends on the pointer being the same, since it sends more than
  11. just the string.
  12. The fix is to subclass the WindowProc on SetWindowText and change the
  13. pointer (in lParam) to the one that was originally passed.
  14. Notes:
  15. This is an app specific shim.
  16. History:
  17. 06/19/2000 linstev Created
  18. --*/
  19. #include "precomp.h"
  20. IMPLEMENT_SHIM_BEGIN(NBALive)
  21. #include "ShimHookMacro.h"
  22. APIHOOK_ENUM_BEGIN
  23. APIHOOK_ENUM_ENTRY(SetWindowTextA)
  24. APIHOOK_ENUM_END
  25. //
  26. // Critical section for global variable access
  27. //
  28. CRITICAL_SECTION g_csGlobals;
  29. //
  30. // Text for window and previous windowproc
  31. //
  32. CHAR *g_szText;
  33. WNDPROC g_lpWndProc;
  34. /*++
  35. The subclassed windowproc that we use to change the text pointer to the
  36. original one passed to SetWindowTextA.
  37. --*/
  38. LRESULT
  39. CALLBACK
  40. WindowProcA(
  41. HWND hWnd,
  42. UINT uMsg,
  43. WPARAM wParam,
  44. LPARAM lParam
  45. )
  46. {
  47. if (uMsg == WM_SETTEXT) {
  48. if (lParam) {
  49. if (strcmp(g_szText, (CHAR *) lParam) == 0) {
  50. lParam = (LPARAM) g_szText;
  51. }
  52. }
  53. }
  54. return CallWindowProcA(g_lpWndProc, hWnd, uMsg, wParam, lParam);
  55. }
  56. /*++
  57. Subclass the windowproc for this call and fix the pointer that comes out in
  58. the WM_SETTEXT message that is generated by SetWindowTextA.
  59. --*/
  60. BOOL
  61. APIHOOK(SetWindowTextA)(
  62. HWND hWnd,
  63. LPCSTR lpString
  64. )
  65. {
  66. BOOL bRet = FALSE;
  67. //
  68. // Set the text for this window
  69. //
  70. EnterCriticalSection(&g_csGlobals);
  71. //
  72. // Subclass the window
  73. //
  74. g_lpWndProc = (WNDPROC) GetWindowLongA(hWnd, GWL_WNDPROC);
  75. if (g_lpWndProc) {
  76. SetWindowLongA(hWnd, GWL_WNDPROC, (LONG_PTR) WindowProcA);
  77. }
  78. //
  79. // Call the original function which generates a WM_SETTEXT message
  80. //
  81. g_szText = (CHAR *) lpString;
  82. bRet = ORIGINAL_API(SetWindowTextA)(hWnd, lpString);
  83. //
  84. // Restore the wndproc
  85. //
  86. SetWindowLongA(hWnd, GWL_WNDPROC, (LONG_PTR) g_lpWndProc);
  87. LeaveCriticalSection(&g_csGlobals);
  88. return bRet;
  89. }
  90. /*++
  91. Register hooked functions
  92. --*/
  93. BOOL
  94. NOTIFY_FUNCTION(
  95. DWORD fdwReason)
  96. {
  97. if (fdwReason == DLL_PROCESS_ATTACH) {
  98. InitializeCriticalSection(&g_csGlobals);
  99. }
  100. return TRUE;
  101. }
  102. HOOK_BEGIN
  103. CALL_NOTIFY_FUNCTION
  104. APIHOOK_ENTRY(USER32.DLL, SetWindowTextA )
  105. HOOK_END
  106. IMPLEMENT_SHIM_END