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.

123 lines
3.5 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: clhook.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Client-side hook code.
  7. *
  8. * 05-09-1991 ScottLu Created.
  9. * 08-Feb-1992 IanJa Unicode/ANSI
  10. \***************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /***************************************************************************\
  14. * SetWindowsHookExAW
  15. *
  16. * Client side routine for SetWindowsHookEx(). Needs to remember the library
  17. * name since hmods aren't global. Remembers the hmod as well so that
  18. * it can be used to calculate pfnFilter in different process contexts.
  19. *
  20. * History:
  21. * 05-15-91 ScottLu Created.
  22. \***************************************************************************/
  23. HHOOK SetWindowsHookExAW(
  24. int idHook,
  25. HOOKPROC lpfn,
  26. HINSTANCE hmod,
  27. DWORD dwThreadID,
  28. DWORD dwFlags)
  29. {
  30. WCHAR pwszLibFileName[MAX_PATH];
  31. /*
  32. * If we're passing an hmod, we need to grab the file name of the
  33. * module while we're still on the client since module handles
  34. * are NOT global.
  35. */
  36. if (hmod != NULL) {
  37. if (GetModuleFileNameW(hmod,
  38. pwszLibFileName,
  39. ARRAY_SIZE(pwszLibFileName)) == 0) {
  40. /*
  41. * hmod is bogus - return NULL.
  42. */
  43. return NULL;
  44. }
  45. }
  46. return _SetWindowsHookEx(hmod,
  47. (hmod == NULL) ? NULL : pwszLibFileName,
  48. dwThreadID, idHook, (PROC)lpfn, dwFlags);
  49. }
  50. /***************************************************************************\
  51. * SetWindowsHookA,
  52. * SetWindowsHookW
  53. *
  54. * ANSI and Unicode wrappers for NtUserSetWindowsHookAW(). Could easily be macros
  55. * instead, but do we want to expose NtUserSetWindowsHookAW() ?
  56. *
  57. * History:
  58. * 30-Jan-1992 IanJa Created
  59. \***************************************************************************/
  60. FUNCLOG2(LOG_GENERAL, HHOOK, WINAPI, SetWindowsHookA, int, nFilterType, HOOKPROC, pfnFilterProc)
  61. HHOOK
  62. WINAPI
  63. SetWindowsHookA(
  64. int nFilterType,
  65. HOOKPROC pfnFilterProc)
  66. {
  67. return NtUserSetWindowsHookAW(nFilterType, pfnFilterProc, HF_ANSI);
  68. }
  69. FUNCLOG2(LOG_GENERAL, HHOOK, WINAPI, SetWindowsHookW, int, nFilterType, HOOKPROC, pfnFilterProc)
  70. HHOOK
  71. WINAPI
  72. SetWindowsHookW(
  73. int nFilterType,
  74. HOOKPROC pfnFilterProc)
  75. {
  76. return NtUserSetWindowsHookAW(nFilterType, pfnFilterProc, 0);
  77. }
  78. /***************************************************************************\
  79. * SetWindowsHookExA,
  80. * SetWindowsHookExW
  81. *
  82. * ANSI and Unicode wrappers for SetWindowsHookExAW(). Could easily be macros
  83. * instead, but do we want to expose SetWindowsHookExAW() ?
  84. *
  85. * History:
  86. * 30-Jan-1992 IanJa Created
  87. \***************************************************************************/
  88. FUNCLOG4(LOG_GENERAL, HHOOK, WINAPI, SetWindowsHookExA, int, idHook, HOOKPROC, lpfn, HINSTANCE, hmod, DWORD, dwThreadId)
  89. HHOOK WINAPI SetWindowsHookExA(
  90. int idHook,
  91. HOOKPROC lpfn,
  92. HINSTANCE hmod,
  93. DWORD dwThreadId)
  94. {
  95. return SetWindowsHookExAW(idHook, lpfn, hmod, dwThreadId, HF_ANSI);
  96. }
  97. FUNCLOG4(LOG_GENERAL, HHOOK, WINAPI, SetWindowsHookExW, int, idHook, HOOKPROC, lpfn, HINSTANCE, hmod, DWORD, dwThreadId)
  98. HHOOK WINAPI SetWindowsHookExW(
  99. int idHook,
  100. HOOKPROC lpfn,
  101. HINSTANCE hmod,
  102. DWORD dwThreadId)
  103. {
  104. return SetWindowsHookExAW(idHook, lpfn, hmod, dwThreadId, 0);
  105. }