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.

246 lines
6.4 KiB

  1. // Utility code for Mapping a WAVE device ID to a DirectSound GUID
  2. // Added - August 24, 1998
  3. // original code in \av\utils\wav2ds
  4. // this code will return an error on Win95
  5. // (although it may work for a future version of DX)
  6. /***************************************************************************
  7. *
  8. * Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
  9. *
  10. * File: dsprvobj.c
  11. * Content: DirectSound Private Object wrapper functions.
  12. * History:
  13. * Date By Reason
  14. * ==== == ======
  15. * 02/12/98 dereks Created.
  16. * 08/24/98 jselbie Streamlined up for lightweight use in NetMeeting
  17. *
  18. ***************************************************************************/
  19. #include "precomp.h"
  20. #include <objbase.h>
  21. #include <initguid.h>
  22. #include <mmsystem.h>
  23. #include <dsound.h>
  24. // DirectSound Private Component GUID {11AB3EC0-25EC-11d1-A4D8-00C04FC28ACA}
  25. DEFINE_GUID(CLSID_DirectSoundPrivate, 0x11ab3ec0, 0x25ec, 0x11d1, 0xa4, 0xd8, 0x0, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
  26. //
  27. // Property Sets
  28. //
  29. // DirectSound Device Properties {84624F82-25EC-11d1-A4D8-00C04FC28ACA}
  30. DEFINE_GUID(DSPROPSETID_DirectSoundDevice, 0x84624f82, 0x25ec, 0x11d1, 0xa4, 0xd8, 0x0, 0xc0, 0x4f, 0xc2, 0x8a, 0xca);
  31. typedef enum
  32. {
  33. DSPROPERTY_DIRECTSOUNDDEVICE_PRESENCE,
  34. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING,
  35. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
  36. DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
  37. } DSPROPERTY_DIRECTSOUNDDEVICE;
  38. typedef enum
  39. {
  40. DIRECTSOUNDDEVICE_DATAFLOW_RENDER,
  41. DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE
  42. } DIRECTSOUNDDEVICE_DATAFLOW;
  43. typedef struct _DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA
  44. {
  45. LPSTR DeviceName; // waveIn/waveOut device name
  46. DIRECTSOUNDDEVICE_DATAFLOW DataFlow; // Data flow (i.e. waveIn or waveOut)
  47. GUID DeviceId; // DirectSound device id
  48. } DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA, *PDSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA;
  49. /***************************************************************************
  50. *
  51. * DirectSoundPrivateCreate
  52. *
  53. * Description:
  54. * Creates and initializes a DirectSoundPrivate object.
  55. *
  56. * Arguments:
  57. * LPKSPROPERTYSET * [out]: receives IKsPropertySet interface to the
  58. * object.
  59. *
  60. * Returns:
  61. * HRESULT: DirectSound/COM result code.
  62. *
  63. ***************************************************************************/
  64. HRESULT
  65. DirectSoundPrivateCreate
  66. (
  67. LPKSPROPERTYSET * ppKsPropertySet
  68. )
  69. {
  70. typedef HRESULT (STDAPICALLTYPE *LPFNDLLGETCLASSOBJECT)(REFCLSID, REFIID, LPVOID *);
  71. HINSTANCE hLibDsound = NULL;
  72. LPFNGETCLASSOBJECT pfnDllGetClassObject = NULL;
  73. LPCLASSFACTORY pClassFactory = NULL;
  74. LPKSPROPERTYSET pKsPropertySet = NULL;
  75. HRESULT hr = DS_OK;
  76. hLibDsound =
  77. GetModuleHandle
  78. (
  79. TEXT("dsound.dll")
  80. );
  81. if(!hLibDsound)
  82. {
  83. hr = DSERR_GENERIC;
  84. }
  85. // Find DllGetClassObject
  86. if(SUCCEEDED(hr))
  87. {
  88. pfnDllGetClassObject = (LPFNDLLGETCLASSOBJECT)
  89. GetProcAddress
  90. (
  91. hLibDsound,
  92. "DllGetClassObject"
  93. );
  94. if(!pfnDllGetClassObject)
  95. {
  96. hr = DSERR_GENERIC;
  97. }
  98. }
  99. // Create a class factory object
  100. if(SUCCEEDED(hr))
  101. {
  102. hr =
  103. pfnDllGetClassObject
  104. (
  105. CLSID_DirectSoundPrivate,
  106. IID_IClassFactory,
  107. (LPVOID *)&pClassFactory
  108. );
  109. }
  110. // Create the DirectSoundPrivate object and query for an IKsPropertySet
  111. // interface
  112. if(SUCCEEDED(hr))
  113. {
  114. hr =
  115. pClassFactory->CreateInstance
  116. (
  117. NULL,
  118. IID_IKsPropertySet,
  119. (LPVOID *)&pKsPropertySet
  120. );
  121. }
  122. // Release the class factory
  123. if(pClassFactory)
  124. {
  125. pClassFactory->Release();
  126. }
  127. // Success
  128. if(SUCCEEDED(hr))
  129. {
  130. *ppKsPropertySet = pKsPropertySet;
  131. }
  132. return hr;
  133. }
  134. /***************************************************************************
  135. *
  136. * DsprvGetWaveDeviceMapping
  137. *
  138. * Description:
  139. * Gets the DirectSound device id (if any) for a given waveIn or
  140. * waveOut device description. This is the description given by
  141. * waveIn/OutGetDevCaps (szPname).
  142. *
  143. * Arguments:
  144. * LPCSTR [in]: wave device description. (WAVEOUTCAPS.szPname or WAVEINCAPS.szPname)
  145. * BOOL [in]: TRUE if the device description refers to a waveIn device.
  146. * LPGUID [out]: receives DirectSound device GUID.
  147. *
  148. * Returns:
  149. * HRESULT: DirectSound/COM result code.
  150. *
  151. ***************************************************************************/
  152. extern "C" HRESULT __stdcall
  153. DsprvGetWaveDeviceMapping
  154. (
  155. LPCSTR pszWaveDevice,
  156. BOOL fCapture,
  157. LPGUID pguidDeviceId
  158. )
  159. {
  160. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA Data;
  161. HRESULT hr;
  162. IKsPropertySet *pKsPropertySet=NULL;
  163. HINSTANCE hLibDsound= NULL;
  164. hLibDsound = NmLoadLibrary(TEXT("dsound.dll"),TRUE);
  165. if (hLibDsound == NULL)
  166. {
  167. return E_FAIL;
  168. }
  169. hr = DirectSoundPrivateCreate(&pKsPropertySet);
  170. if (SUCCEEDED(hr))
  171. {
  172. Data.DeviceName = (LPSTR)pszWaveDevice;
  173. Data.DataFlow = fCapture ? DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE : DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
  174. hr =
  175. pKsPropertySet->Get
  176. (
  177. DSPROPSETID_DirectSoundDevice,
  178. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING,
  179. NULL,
  180. 0,
  181. &Data,
  182. sizeof(Data),
  183. NULL
  184. );
  185. if(SUCCEEDED(hr))
  186. {
  187. *pguidDeviceId = Data.DeviceId;
  188. }
  189. else
  190. {
  191. ZeroMemory(pguidDeviceId, sizeof(GUID));
  192. }
  193. }
  194. if (pKsPropertySet)
  195. pKsPropertySet->Release();
  196. FreeLibrary(hLibDsound);
  197. return hr;
  198. }