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.

211 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. CorrectSoundDeviceId.cpp
  5. Abstract:
  6. This shim fixes calls to waveOutOpen, waveOutGetDevCaps, midiOutOpen and
  7. midiOutGetDevCaps with the uDeviceID equal to 0xFFFF, which was the constant
  8. for Wave/MIDI Mapper under 16-bit windows. Under 32-bit the new constant is
  9. 0xFFFFFFFF. This is going to be fixed in winmm code for Whistler but we still
  10. keep this shim to fix apps on w2k.
  11. Notes:
  12. This is a general purpose shim.
  13. History:
  14. 01/26/2000 dmunsil Created
  15. 10/09/2000 maonis Added hooks for midiOutGetDevCaps and midiOutOpen.
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(CorrectSoundDeviceId)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(waveOutOpen)
  22. APIHOOK_ENUM_ENTRY(waveOutGetDevCapsA)
  23. APIHOOK_ENUM_ENTRY(waveOutGetDevCapsW)
  24. APIHOOK_ENUM_ENTRY(midiOutOpen)
  25. APIHOOK_ENUM_ENTRY(midiOutGetDevCapsA)
  26. APIHOOK_ENUM_END
  27. /*++
  28. This stub function fixes calls with the uDeviceID equal to 0xFFFF, which was
  29. the constant for Wave Mapper under 16-bit windows.
  30. --*/
  31. MMRESULT
  32. APIHOOK(waveOutOpen)(
  33. LPHWAVEOUT phwo, // return buffer
  34. UINT uDeviceID, // id of the device to use
  35. LPWAVEFORMATEX pwfx, // what format you need (i.e. 11K, 16bit, stereo)
  36. DWORD dwCallback, // callback for notification on buffer completion
  37. DWORD dwCallbackInstance, // instance handle for callback
  38. DWORD fdwOpen // flags
  39. )
  40. {
  41. if (uDeviceID == 0xFFFF) {
  42. LOGN(
  43. eDbgLevelError,
  44. "[waveOutOpen] Fixed invalid Wave Mapper device ID.");
  45. uDeviceID = (UINT)-1;
  46. }
  47. return ORIGINAL_API(waveOutOpen)(
  48. phwo,
  49. uDeviceID,
  50. pwfx,
  51. dwCallback,
  52. dwCallbackInstance,
  53. fdwOpen);
  54. }
  55. /*++
  56. This stub function fixes calls with the uDeviceID equal to 0xFFFF, which was
  57. the constant for Wave Mapper under 16-bit windows.
  58. --*/
  59. MMRESULT
  60. APIHOOK(waveOutGetDevCapsA)(
  61. UINT uDeviceID, // id of the device to use
  62. LPWAVEOUTCAPSA pwoc, // returned caps structure
  63. UINT cbwoc // size in bytes of the WAVEOUTCAPS struct
  64. )
  65. {
  66. if (uDeviceID == 0xFFFF) {
  67. LOGN(
  68. eDbgLevelError,
  69. "[waveOutGetDevCapsA] Fixed invalid Wave Mapper device ID.");
  70. uDeviceID = (UINT)-1;
  71. }
  72. return ORIGINAL_API(waveOutGetDevCapsA)(
  73. uDeviceID,
  74. pwoc,
  75. cbwoc);
  76. }
  77. /*++
  78. This stub function fixes calls with the uDeviceID equal to 0xFFFF, which was
  79. the constant for Wave Mapper under 16-bit windows.
  80. --*/
  81. MMRESULT
  82. APIHOOK(waveOutGetDevCapsW)(
  83. UINT uDeviceID, // id of the device to use
  84. LPWAVEOUTCAPSW pwoc, // returned caps structure
  85. UINT cbwoc // size in bytes of the WAVEOUTCAPS struct
  86. )
  87. {
  88. if (uDeviceID == 0xFFFF) {
  89. LOGN(
  90. eDbgLevelError,
  91. "[waveOutGetDevCapsW] Fixed invalid Wave Mapper device ID.");
  92. uDeviceID = (UINT)-1;
  93. }
  94. return ORIGINAL_API(waveOutGetDevCapsW)(
  95. uDeviceID,
  96. pwoc,
  97. cbwoc);
  98. }
  99. /*++
  100. This stub function fixes calls with the uDeviceID equal to 0xFFFF, which was
  101. the constant for MIDI Mapper under 16-bit windows.
  102. --*/
  103. MMRESULT
  104. APIHOOK(midiOutOpen)(
  105. LPHMIDIOUT phmo,
  106. UINT uDeviceID,
  107. DWORD_PTR dwCallback,
  108. DWORD_PTR dwInstance,
  109. DWORD fdwOpen
  110. )
  111. {
  112. if (uDeviceID == 0xffff) {
  113. LOGN(
  114. eDbgLevelError,
  115. "[midiOutOpen] Fixed invalid MIDI Mapper device ID.");
  116. uDeviceID = (UINT)-1;
  117. }
  118. return ORIGINAL_API(midiOutOpen)(
  119. phmo,
  120. uDeviceID,
  121. dwCallback,
  122. dwInstance,
  123. fdwOpen);
  124. }
  125. /*++
  126. This stub function fixes calls with the uDeviceID equal to 0xFFFF, which was
  127. the constant for MIDI Mapper under 16-bit windows.
  128. --*/
  129. MMRESULT
  130. APIHOOK(midiOutGetDevCapsA)(
  131. UINT_PTR uDeviceID,
  132. LPMIDIOUTCAPSA pmoc,
  133. UINT cbmoc
  134. )
  135. {
  136. if (uDeviceID == 0xffff) {
  137. LOGN(
  138. eDbgLevelError,
  139. "[midiOutGetDevCapsA] Fixed invalid MIDI Mapper device ID.");
  140. uDeviceID = (UINT)-1;
  141. }
  142. return ORIGINAL_API(midiOutGetDevCapsA)(
  143. uDeviceID,
  144. pmoc,
  145. cbmoc);
  146. }
  147. /*++
  148. Register hooked functions
  149. --*/
  150. HOOK_BEGIN
  151. APIHOOK_ENTRY(WINMM.DLL, waveOutOpen)
  152. APIHOOK_ENTRY(WINMM.DLL, waveOutGetDevCapsA)
  153. APIHOOK_ENTRY(WINMM.DLL, waveOutGetDevCapsW)
  154. APIHOOK_ENTRY(WINMM.DLL, midiOutOpen)
  155. APIHOOK_ENTRY(WINMM.DLL, midiOutGetDevCapsA)
  156. HOOK_END
  157. IMPLEMENT_SHIM_END