pa_win_ds_dynlink.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Interface for dynamically loading directsound and providing a dummy
  3. * implementation if it isn't present.
  4. *
  5. * Author: Ross Bencina (some portions Phil Burk & Robert Marsanyi)
  6. *
  7. * For PortAudio Portable Real-Time Audio Library
  8. * For more information see: http://www.portaudio.com
  9. * Copyright (c) 1999-2006 Phil Burk, Robert Marsanyi and Ross Bencina
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files
  13. * (the "Software"), to deal in the Software without restriction,
  14. * including without limitation the rights to use, copy, modify, merge,
  15. * publish, distribute, sublicense, and/or sell copies of the Software,
  16. * and to permit persons to whom the Software is furnished to do so,
  17. * subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  26. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  27. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. /*
  31. * The text above constitutes the entire PortAudio license; however,
  32. * the PortAudio community also makes the following non-binding requests:
  33. *
  34. * Any person wishing to distribute modifications to the Software is
  35. * requested to send the modifications to the original developer so that
  36. * they can be incorporated into the canonical version. It is also
  37. * requested that these non-binding requests be included along with the
  38. * license above.
  39. */
  40. /**
  41. @file
  42. @ingroup hostapi_src
  43. */
  44. #include "pa_win_ds_dynlink.h"
  45. #include "pa_debugprint.h"
  46. PaWinDsDSoundEntryPoints paWinDsDSoundEntryPoints = { 0, 0, 0, 0, 0, 0, 0 };
  47. static HRESULT WINAPI DummyDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
  48. {
  49. (void)rclsid; /* unused parameter */
  50. (void)riid; /* unused parameter */
  51. (void)ppv; /* unused parameter */
  52. return CLASS_E_CLASSNOTAVAILABLE;
  53. }
  54. static HRESULT WINAPI DummyDirectSoundCreate(LPGUID lpcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter)
  55. {
  56. (void)lpcGuidDevice; /* unused parameter */
  57. (void)ppDS; /* unused parameter */
  58. (void)pUnkOuter; /* unused parameter */
  59. return E_NOTIMPL;
  60. }
  61. static HRESULT WINAPI DummyDirectSoundEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
  62. {
  63. (void)lpDSEnumCallback; /* unused parameter */
  64. (void)lpContext; /* unused parameter */
  65. return E_NOTIMPL;
  66. }
  67. static HRESULT WINAPI DummyDirectSoundEnumerateA(LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext)
  68. {
  69. (void)lpDSEnumCallback; /* unused parameter */
  70. (void)lpContext; /* unused parameter */
  71. return E_NOTIMPL;
  72. }
  73. static HRESULT WINAPI DummyDirectSoundCaptureCreate(LPGUID lpcGUID, LPDIRECTSOUNDCAPTURE *lplpDSC, LPUNKNOWN pUnkOuter)
  74. {
  75. (void)lpcGUID; /* unused parameter */
  76. (void)lplpDSC; /* unused parameter */
  77. (void)pUnkOuter; /* unused parameter */
  78. return E_NOTIMPL;
  79. }
  80. static HRESULT WINAPI DummyDirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW lpDSCEnumCallback, LPVOID lpContext)
  81. {
  82. (void)lpDSCEnumCallback; /* unused parameter */
  83. (void)lpContext; /* unused parameter */
  84. return E_NOTIMPL;
  85. }
  86. static HRESULT WINAPI DummyDirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA lpDSCEnumCallback, LPVOID lpContext)
  87. {
  88. (void)lpDSCEnumCallback; /* unused parameter */
  89. (void)lpContext; /* unused parameter */
  90. return E_NOTIMPL;
  91. }
  92. #ifdef PAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE
  93. static HRESULT WINAPI DummyDirectSoundFullDuplexCreate8(
  94. LPCGUID pcGuidCaptureDevice,
  95. LPCGUID pcGuidRenderDevice,
  96. LPCDSCBUFFERDESC pcDSCBufferDesc,
  97. LPCDSBUFFERDESC pcDSBufferDesc,
  98. HWND hWnd,
  99. DWORD dwLevel,
  100. LPDIRECTSOUNDFULLDUPLEX * ppDSFD,
  101. LPDIRECTSOUNDCAPTUREBUFFER8 * ppDSCBuffer8,
  102. LPDIRECTSOUNDBUFFER8 * ppDSBuffer8,
  103. LPUNKNOWN pUnkOuter)
  104. {
  105. (void)pcGuidCaptureDevice; /* unused parameter */
  106. (void)pcGuidRenderDevice; /* unused parameter */
  107. (void)pcDSCBufferDesc; /* unused parameter */
  108. (void)pcDSBufferDesc; /* unused parameter */
  109. (void)hWnd; /* unused parameter */
  110. (void)dwLevel; /* unused parameter */
  111. (void)ppDSFD; /* unused parameter */
  112. (void)ppDSCBuffer8; /* unused parameter */
  113. (void)ppDSBuffer8; /* unused parameter */
  114. (void)pUnkOuter; /* unused parameter */
  115. return E_NOTIMPL;
  116. }
  117. #endif /* PAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE */
  118. void PaWinDs_InitializeDSoundEntryPoints(void)
  119. {
  120. paWinDsDSoundEntryPoints.hInstance_ = LoadLibraryA("dsound.dll");
  121. if( paWinDsDSoundEntryPoints.hInstance_ != NULL )
  122. {
  123. paWinDsDSoundEntryPoints.DllGetClassObject =
  124. (HRESULT (WINAPI *)(REFCLSID, REFIID , LPVOID *))
  125. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DllGetClassObject" );
  126. if( paWinDsDSoundEntryPoints.DllGetClassObject == NULL )
  127. paWinDsDSoundEntryPoints.DllGetClassObject = DummyDllGetClassObject;
  128. paWinDsDSoundEntryPoints.DirectSoundCreate =
  129. (HRESULT (WINAPI *)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN))
  130. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundCreate" );
  131. if( paWinDsDSoundEntryPoints.DirectSoundCreate == NULL )
  132. paWinDsDSoundEntryPoints.DirectSoundCreate = DummyDirectSoundCreate;
  133. paWinDsDSoundEntryPoints.DirectSoundEnumerateW =
  134. (HRESULT (WINAPI *)(LPDSENUMCALLBACKW, LPVOID))
  135. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundEnumerateW" );
  136. if( paWinDsDSoundEntryPoints.DirectSoundEnumerateW == NULL )
  137. paWinDsDSoundEntryPoints.DirectSoundEnumerateW = DummyDirectSoundEnumerateW;
  138. paWinDsDSoundEntryPoints.DirectSoundEnumerateA =
  139. (HRESULT (WINAPI *)(LPDSENUMCALLBACKA, LPVOID))
  140. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundEnumerateA" );
  141. if( paWinDsDSoundEntryPoints.DirectSoundEnumerateA == NULL )
  142. paWinDsDSoundEntryPoints.DirectSoundEnumerateA = DummyDirectSoundEnumerateA;
  143. paWinDsDSoundEntryPoints.DirectSoundCaptureCreate =
  144. (HRESULT (WINAPI *)(LPGUID, LPDIRECTSOUNDCAPTURE *, LPUNKNOWN))
  145. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundCaptureCreate" );
  146. if( paWinDsDSoundEntryPoints.DirectSoundCaptureCreate == NULL )
  147. paWinDsDSoundEntryPoints.DirectSoundCaptureCreate = DummyDirectSoundCaptureCreate;
  148. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW =
  149. (HRESULT (WINAPI *)(LPDSENUMCALLBACKW, LPVOID))
  150. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundCaptureEnumerateW" );
  151. if( paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW == NULL )
  152. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW = DummyDirectSoundCaptureEnumerateW;
  153. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA =
  154. (HRESULT (WINAPI *)(LPDSENUMCALLBACKA, LPVOID))
  155. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundCaptureEnumerateA" );
  156. if( paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA == NULL )
  157. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA = DummyDirectSoundCaptureEnumerateA;
  158. #ifdef PAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE
  159. paWinDsDSoundEntryPoints.DirectSoundFullDuplexCreate8 =
  160. (HRESULT (WINAPI *)(LPCGUID, LPCGUID, LPCDSCBUFFERDESC, LPCDSBUFFERDESC,
  161. HWND, DWORD, LPDIRECTSOUNDFULLDUPLEX *, LPDIRECTSOUNDCAPTUREBUFFER8 *,
  162. LPDIRECTSOUNDBUFFER8 *, LPUNKNOWN))
  163. GetProcAddress( paWinDsDSoundEntryPoints.hInstance_, "DirectSoundFullDuplexCreate" );
  164. if( paWinDsDSoundEntryPoints.DirectSoundFullDuplexCreate8 == NULL )
  165. paWinDsDSoundEntryPoints.DirectSoundFullDuplexCreate8 = DummyDirectSoundFullDuplexCreate8;
  166. #endif
  167. }
  168. else
  169. {
  170. DWORD errorCode = GetLastError(); // 126 (0x7E) == ERROR_MOD_NOT_FOUND
  171. PA_DEBUG(("Couldn't load dsound.dll error code: %d \n",errorCode));
  172. /* initialize with dummy entry points to make live easy when ds isn't present */
  173. paWinDsDSoundEntryPoints.DirectSoundCreate = DummyDirectSoundCreate;
  174. paWinDsDSoundEntryPoints.DirectSoundEnumerateW = DummyDirectSoundEnumerateW;
  175. paWinDsDSoundEntryPoints.DirectSoundEnumerateA = DummyDirectSoundEnumerateA;
  176. paWinDsDSoundEntryPoints.DirectSoundCaptureCreate = DummyDirectSoundCaptureCreate;
  177. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW = DummyDirectSoundCaptureEnumerateW;
  178. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA = DummyDirectSoundCaptureEnumerateA;
  179. #ifdef PAWIN_USE_DIRECTSOUNDFULLDUPLEXCREATE
  180. paWinDsDSoundEntryPoints.DirectSoundFullDuplexCreate8 = DummyDirectSoundFullDuplexCreate8;
  181. #endif
  182. }
  183. }
  184. void PaWinDs_TerminateDSoundEntryPoints(void)
  185. {
  186. if( paWinDsDSoundEntryPoints.hInstance_ != NULL )
  187. {
  188. /* ensure that we crash reliably if the entry points arent initialised */
  189. paWinDsDSoundEntryPoints.DirectSoundCreate = 0;
  190. paWinDsDSoundEntryPoints.DirectSoundEnumerateW = 0;
  191. paWinDsDSoundEntryPoints.DirectSoundEnumerateA = 0;
  192. paWinDsDSoundEntryPoints.DirectSoundCaptureCreate = 0;
  193. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW = 0;
  194. paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA = 0;
  195. FreeLibrary( paWinDsDSoundEntryPoints.hInstance_ );
  196. paWinDsDSoundEntryPoints.hInstance_ = NULL;
  197. }
  198. }