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.

146 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. EmulatePlaySound.cpp
  5. Abstract:
  6. If an app calls PlaySound with a SND_LOOP flag, the sould plays
  7. continuously until PlaySound is called with a NULL sound name. Win9x will
  8. automatically stop the sound if a different sound is played. This shim
  9. will catch all PlaySound calls, remember the current sound and
  10. automatically stop it if a different sound is to be played.
  11. History:
  12. 04/05/1999 robkenny
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(EmulatePlaySound)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(PlaySoundA)
  19. APIHOOK_ENUM_ENTRY(PlaySoundW)
  20. APIHOOK_ENUM_ENTRY(sndPlaySoundA)
  21. APIHOOK_ENUM_ENTRY(sndPlaySoundW)
  22. APIHOOK_ENUM_END
  23. /*++
  24. Fix the flags
  25. --*/
  26. BOOL
  27. APIHOOK(PlaySoundA)(
  28. LPCSTR pszSound,
  29. HMODULE hmod,
  30. DWORD fdwSound
  31. )
  32. {
  33. //
  34. // Force the flags to 0 if they want to stop the current sound.
  35. //
  36. if (pszSound == NULL) {
  37. fdwSound = 0;
  38. }
  39. return ORIGINAL_API(PlaySoundA)(pszSound, hmod, fdwSound);
  40. }
  41. /*++
  42. Fix the flags
  43. --*/
  44. BOOL
  45. APIHOOK(PlaySoundW)(
  46. LPCWSTR pszSound,
  47. HMODULE hmod,
  48. DWORD fdwSound
  49. )
  50. {
  51. //
  52. // Force the flags to 0 if they want to stop the current sound.
  53. //
  54. if (pszSound == NULL) {
  55. fdwSound = 0;
  56. }
  57. return ORIGINAL_API(PlaySoundW)(pszSound, hmod, fdwSound);
  58. }
  59. /*++
  60. Fix the flags
  61. --*/
  62. BOOL
  63. APIHOOK(sndPlaySoundA)(
  64. LPCSTR pszSound,
  65. UINT fuSound
  66. )
  67. {
  68. //
  69. // Force the flags to 0 if they want to stop the current sound.
  70. //
  71. if (pszSound == NULL) {
  72. fuSound = 0;
  73. }
  74. return ORIGINAL_API(sndPlaySoundA)(pszSound, fuSound);
  75. }
  76. /*++
  77. Fix the flags.
  78. --*/
  79. BOOL
  80. APIHOOK(sndPlaySoundW)(
  81. LPCWSTR pszSound,
  82. UINT fuSound
  83. )
  84. {
  85. //
  86. // Force the flags to 0 if they want to stop the current sound.
  87. //
  88. if (pszSound == NULL) {
  89. fuSound = 0;
  90. }
  91. return ORIGINAL_API(sndPlaySoundW)(pszSound, fuSound);
  92. }
  93. /*++
  94. Register hooked functions
  95. --*/
  96. HOOK_BEGIN
  97. APIHOOK_ENTRY(WINMM.DLL, PlaySoundA)
  98. APIHOOK_ENTRY(WINMM.DLL, PlaySoundW)
  99. APIHOOK_ENTRY(WINMM.DLL, sndPlaySoundA)
  100. APIHOOK_ENTRY(WINMM.DLL, sndPlaySoundW)
  101. HOOK_END
  102. IMPLEMENT_SHIM_END