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.

103 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. PostIt2.cpp
  5. Abstract:
  6. This shim eliminates an infinite loop in 3M's Post-It Notes application
  7. by preventing the WM_TIMECHANGE message from reaching the Post-It
  8. Notes windows when the application triggers a time change using
  9. SetTimeZoneInformation().
  10. Notes:
  11. This is an application specific shim.
  12. History:
  13. 06/04/2001 tonyschr Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(PostIt2)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(SetTimeZoneInformation)
  20. APIHOOK_ENUM_ENTRY(CallWindowProcA)
  21. APIHOOK_ENUM_END
  22. static SYSTEMTIME g_localtime = { 0 };
  23. BOOL
  24. APIHOOK(SetTimeZoneInformation)(
  25. CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation
  26. )
  27. {
  28. BOOL fReturn = ORIGINAL_API(SetTimeZoneInformation)(lpTimeZoneInformation);
  29. // Store off local time after this application requests timezone change.
  30. GetLocalTime(&g_localtime);
  31. return fReturn;
  32. }
  33. LRESULT
  34. APIHOOK(CallWindowProcA)(
  35. WNDPROC pfn,
  36. HWND hwnd,
  37. UINT message,
  38. WPARAM wParam,
  39. LPARAM lParam)
  40. {
  41. // Detect whether the WM_TIMECHANGE message was triggered by the app calling
  42. // SetTimeZoneInformation() or an external timechange by comparing the local
  43. // time.
  44. if (message == WM_TIMECHANGE)
  45. {
  46. SYSTEMTIME newtime;
  47. GetLocalTime(&newtime);
  48. if (newtime.wYear == g_localtime.wYear &&
  49. newtime.wMonth == g_localtime.wMonth &&
  50. newtime.wDayOfWeek == g_localtime.wDayOfWeek &&
  51. newtime.wDay == g_localtime.wDay &&
  52. newtime.wHour == g_localtime.wHour &&
  53. newtime.wMinute == g_localtime.wMinute &&
  54. newtime.wSecond == g_localtime.wSecond &&
  55. newtime.wMilliseconds == g_localtime.wMilliseconds)
  56. {
  57. // Looks like this WM_TIMECHANGE was sent in response to the app
  58. // calling SetTimeZoneInformation(), so block it.
  59. // Note: Because of the asynchronous nature of window messages this
  60. // might let an occasional WM_TIMECHANGE slip through, but it should
  61. // always terminiate the infinite loop.
  62. return 0;
  63. }
  64. }
  65. return ORIGINAL_API(CallWindowProcA)(pfn, hwnd, message, wParam, lParam);
  66. }
  67. /*++
  68. Register hooked functions
  69. --*/
  70. HOOK_BEGIN
  71. APIHOOK_ENTRY(KERNEL32.DLL, SetTimeZoneInformation)
  72. APIHOOK_ENTRY(USER32.DLL, CallWindowProcA)
  73. HOOK_END
  74. IMPLEMENT_SHIM_END