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.

104 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. LazyReleaseDC.cpp
  5. Abstract:
  6. Delay releasing a DC by one call. A DC is not released until the next call to ReleaseDC
  7. Notes:
  8. This is a general purpose shim.
  9. History:
  10. 10/10/1999 linstev Created
  11. 02/05/2002 mnikkel Changed InitializeCriticalSection to InitializeCriticalSectionAndSpinCount
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(LazyReleaseDC)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(ReleaseDC)
  18. APIHOOK_ENUM_END
  19. HWND g_hWndPrev;
  20. HDC g_hDcPrev;
  21. CRITICAL_SECTION g_MakeThreadSafe;
  22. /*++
  23. Save this hWnd and hdc for releasing later. If there is already a DC to be
  24. released, release it now.
  25. --*/
  26. int
  27. APIHOOK(ReleaseDC)(
  28. HWND hWnd,
  29. HDC hdc
  30. )
  31. {
  32. UINT uRet = 1; // All's well
  33. EnterCriticalSection(&g_MakeThreadSafe);
  34. // If there is a previous DC, release it now
  35. if (g_hDcPrev) {
  36. uRet = ORIGINAL_API(ReleaseDC)(g_hWndPrev, g_hDcPrev);
  37. }
  38. g_hWndPrev = hWnd;
  39. g_hDcPrev = hdc;
  40. LeaveCriticalSection(&g_MakeThreadSafe);
  41. return uRet;
  42. }
  43. /*++
  44. Register hooked functions
  45. --*/
  46. BOOL
  47. NOTIFY_FUNCTION(
  48. DWORD fdwReason
  49. )
  50. {
  51. if (fdwReason == DLL_PROCESS_ATTACH) {
  52. g_hWndPrev = 0;
  53. g_hDcPrev = 0;
  54. return InitializeCriticalSectionAndSpinCount(&g_MakeThreadSafe,0x80000000);
  55. }
  56. // Ignore Detach code
  57. /*
  58. else if (fdwReason == DLL_PROCESS_DETACH) {
  59. DeleteCriticalSection(&g_MakeThreadSafe);
  60. }
  61. */
  62. return TRUE;
  63. }
  64. HOOK_BEGIN
  65. CALL_NOTIFY_FUNCTION
  66. APIHOOK_ENTRY(USER32.DLL, ReleaseDC)
  67. HOOK_END
  68. IMPLEMENT_SHIM_END