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.

102 lines
2.8 KiB

  1. #include "stdafx.h"
  2. #include "Services.h"
  3. #include "Hook.h"
  4. #if ENABLE_MPH
  5. typedef BOOL (WINAPI * RegisterMPHProc)(INITMESSAGEPUMPHOOK pfnInitMPH);
  6. typedef BOOL (WINAPI * UnregisterMPHProc)();
  7. //------------------------------------------------------------------------------
  8. // Forward declarations of implementation functions declared in other modules.
  9. //
  10. BOOL CALLBACK MphProcessMessage(MSG * pmsg, HWND hwnd,
  11. UINT wMsgFilterMin, UINT wMsgFilterMax, UINT flags, BOOL fGetMessage);
  12. BOOL CALLBACK MphWaitMessageEx(UINT fsWakeMask, DWORD dwTimeOut);
  13. //------------------------------------------------------------------------------
  14. BOOL InitMPH()
  15. {
  16. BOOL fSuccess = FALSE;
  17. HINSTANCE hinst = LoadLibrary("user32.dll");
  18. if (hinst != NULL) {
  19. RegisterMPHProc pfnInit = (RegisterMPHProc) GetProcAddress(hinst, "RegisterMessagePumpHook");
  20. if (pfnInit != NULL) {
  21. fSuccess = (pfnInit)(DUserInitHook);
  22. }
  23. }
  24. return fSuccess;
  25. }
  26. //------------------------------------------------------------------------------
  27. BOOL UninitMPH()
  28. {
  29. BOOL fSuccess = FALSE;
  30. HINSTANCE hinst = LoadLibrary("user32.dll");
  31. if (hinst != NULL) {
  32. UnregisterMPHProc pfnUninit = (UnregisterMPHProc) GetProcAddress(hinst, "UnregisterMessagePumpHook");
  33. AssertMsg(pfnUninit != NULL, "Must have Uninit function");
  34. if (pfnUninit != NULL) {
  35. fSuccess = (pfnUninit)();
  36. }
  37. }
  38. return fSuccess;
  39. }
  40. //------------------------------------------------------------------------------
  41. BOOL CALLBACK DUserInitHook(DWORD dwCmd, void* pvParam)
  42. {
  43. BOOL fSuccess = FALSE;
  44. switch (dwCmd)
  45. {
  46. case UIAH_INITIALIZE:
  47. {
  48. //
  49. // Setting up the hooks:
  50. // - Copy the "real" functions over so that DUser can call them later
  51. // - Replace the functions that DUser needs to override
  52. //
  53. MESSAGEPUMPHOOK * pmphReal = reinterpret_cast<MESSAGEPUMPHOOK *>(pvParam);
  54. if ((pmphReal == NULL) || (pmphReal->cbSize < sizeof(MESSAGEPUMPHOOK))) {
  55. break;
  56. }
  57. CopyMemory(&g_mphReal, pmphReal, pmphReal->cbSize);
  58. pmphReal->cbSize = sizeof(MESSAGEPUMPHOOK);
  59. pmphReal->pfnInternalGetMessage
  60. = MphProcessMessage;
  61. pmphReal->pfnWaitMessageEx = MphWaitMessageEx;
  62. fSuccess = TRUE;
  63. }
  64. break;
  65. case UIAH_UNINITIALIZE:
  66. //
  67. // When uninitializing, NULL our function pointers.
  68. //
  69. ZeroMemory(&g_mphReal, sizeof(g_mphReal));
  70. fSuccess = TRUE;
  71. break;
  72. default:
  73. Trace("DUSER: Unknown dwCmd: %d\n", dwCmd);
  74. }
  75. return fSuccess;
  76. }
  77. #endif // ENABLE_MPH