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.

401 lines
10 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dsprvobj.c
  6. * Content: DirectSound Private Object wrapper functions.
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 02/12/98 dereks Created.
  11. *
  12. ***************************************************************************/
  13. #define DIRECTSOUND_VERSION 0x0600
  14. // We'll ask for what we need, thank you.
  15. #ifndef WIN32_LEAN_AND_MEAN
  16. #define WIN32_LEAN_AND_MEAN
  17. #endif // WIN32_LEAN_AND_MEAN
  18. // Public includes
  19. #include <windows.h>
  20. #include <mmsystem.h>
  21. #include <dsound.h>
  22. #include "dsprv.h"
  23. // Private includes
  24. #include "dsprvobj.h"
  25. /***************************************************************************
  26. *
  27. * DirectSoundPrivateCreate
  28. *
  29. * Description:
  30. * Creates and initializes a DirectSoundPrivate object.
  31. *
  32. * Arguments:
  33. * LPKSPROPERTYSET * [out]: receives IKsPropertySet interface to the
  34. * object.
  35. *
  36. * Returns:
  37. * HRESULT: DirectSound/COM result code.
  38. *
  39. ***************************************************************************/
  40. HRESULT DirectSoundPrivateCreate
  41. (
  42. LPKSPROPERTYSET * ppKsPropertySet
  43. )
  44. {
  45. typedef HRESULT (STDAPICALLTYPE *LPFNDLLGETCLASSOBJECT)(REFCLSID, REFIID, LPVOID *);
  46. HINSTANCE hLibDsound = NULL;
  47. LPFNGETCLASSOBJECT pfnDllGetClassObject = NULL;
  48. LPCLASSFACTORY pClassFactory = NULL;
  49. LPKSPROPERTYSET pKsPropertySet = NULL;
  50. HRESULT hr = DS_OK;
  51. // Get dsound.dll's instance handle. The dll must already be loaded at this
  52. // point.
  53. hLibDsound =
  54. GetModuleHandle
  55. (
  56. TEXT("dsound.dll")
  57. );
  58. if(!hLibDsound)
  59. {
  60. hr = DSERR_GENERIC;
  61. }
  62. // Find DllGetClassObject
  63. if(SUCCEEDED(hr))
  64. {
  65. pfnDllGetClassObject = (LPFNDLLGETCLASSOBJECT)
  66. GetProcAddress
  67. (
  68. hLibDsound,
  69. "DllGetClassObject"
  70. );
  71. if(!pfnDllGetClassObject)
  72. {
  73. hr = DSERR_GENERIC;
  74. }
  75. }
  76. // Create a class factory object
  77. if(SUCCEEDED(hr))
  78. {
  79. hr =
  80. pfnDllGetClassObject
  81. (
  82. CLSID_DirectSoundPrivate,
  83. IID_IClassFactory,
  84. (LPVOID *)&pClassFactory
  85. );
  86. }
  87. // Create the DirectSoundPrivate object and query for an IKsPropertySet
  88. // interface
  89. if(SUCCEEDED(hr))
  90. {
  91. hr =
  92. pClassFactory->CreateInstance
  93. (
  94. NULL,
  95. IID_IKsPropertySet,
  96. (LPVOID *)&pKsPropertySet
  97. );
  98. }
  99. // Release the class factory
  100. if(pClassFactory)
  101. {
  102. pClassFactory->Release();
  103. }
  104. // Success
  105. if(SUCCEEDED(hr))
  106. {
  107. *ppKsPropertySet = pKsPropertySet;
  108. }
  109. return hr;
  110. }
  111. /***************************************************************************
  112. *
  113. * PrvGetDeviceDescription
  114. *
  115. * Description:
  116. * Gets the extended description for a given DirectSound device.
  117. *
  118. * Arguments:
  119. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  120. * DirectSoundPrivate object.
  121. * REFGUID [in]: DirectSound device id.
  122. * PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA [out]: receives
  123. * description.
  124. *
  125. * Returns:
  126. * HRESULT: DirectSound/COM result code.
  127. *
  128. ***************************************************************************/
  129. HRESULT PrvGetDeviceDescription
  130. (
  131. LPKSPROPERTYSET pKsPropertySet,
  132. REFGUID guidDeviceId,
  133. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA *ppData
  134. )
  135. {
  136. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA pData = NULL;
  137. ULONG cbData;
  138. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA Basic;
  139. HRESULT hr;
  140. Basic.DeviceId = guidDeviceId;
  141. hr =
  142. pKsPropertySet->Get
  143. (
  144. DSPROPSETID_DirectSoundDevice,
  145. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
  146. NULL,
  147. 0,
  148. &Basic,
  149. sizeof(Basic),
  150. &cbData
  151. );
  152. if(SUCCEEDED(hr))
  153. {
  154. pData = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA)new BYTE [cbData];
  155. if(!pData)
  156. {
  157. hr = DSERR_OUTOFMEMORY;
  158. }
  159. }
  160. if(SUCCEEDED(hr))
  161. {
  162. ZeroMemory(pData, cbData);
  163. pData->DeviceId = guidDeviceId;
  164. hr =
  165. pKsPropertySet->Get
  166. (
  167. DSPROPSETID_DirectSoundDevice,
  168. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
  169. NULL,
  170. 0,
  171. pData,
  172. cbData,
  173. NULL
  174. );
  175. }
  176. if(SUCCEEDED(hr))
  177. {
  178. *ppData = pData;
  179. }
  180. else if(pData)
  181. {
  182. delete[] pData;
  183. }
  184. return hr;
  185. }
  186. /***************************************************************************
  187. *
  188. * PrvReleaseDeviceDescription
  189. *
  190. ***************************************************************************/
  191. HRESULT PrvReleaseDeviceDescription( PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA pData )
  192. {
  193. delete[] pData;
  194. return S_OK;
  195. }
  196. /***************************************************************************
  197. *
  198. * PrvGetBasicAcceleration
  199. *
  200. * Description:
  201. * Gets basic acceleration flags for a given DirectSound device. This
  202. * is the accleration level that the multimedia control panel uses.
  203. *
  204. * Arguments:
  205. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  206. * DirectSoundPrivate object.
  207. * REFGUID [in]: DirectSound device GUID.
  208. * DIRECTSOUNDBASICACCELERATION_LEVEL * [out]: receives basic
  209. * acceleration level.
  210. *
  211. * Returns:
  212. * HRESULT: DirectSound/COM result code.
  213. *
  214. ***************************************************************************/
  215. HRESULT PrvGetBasicAcceleration
  216. (
  217. LPKSPROPERTYSET pKsPropertySet,
  218. REFGUID guidDeviceId,
  219. DIRECTSOUNDBASICACCELERATION_LEVEL * pLevel
  220. )
  221. {
  222. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION_DATA Data;
  223. HRESULT hr;
  224. Data.DeviceId = guidDeviceId;
  225. hr =
  226. pKsPropertySet->Get
  227. (
  228. DSPROPSETID_DirectSoundBasicAcceleration,
  229. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION,
  230. NULL,
  231. 0,
  232. &Data,
  233. sizeof(Data),
  234. NULL
  235. );
  236. if(SUCCEEDED(hr))
  237. {
  238. *pLevel = Data.Level;
  239. }
  240. return hr;
  241. }
  242. /***************************************************************************
  243. *
  244. * PrvSetBasicAcceleration
  245. *
  246. * Description:
  247. * Sets basic acceleration flags for a given DirectSound device. This
  248. * is the accleration level that the multimedia control panel uses.
  249. *
  250. * Arguments:
  251. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  252. * DirectSoundPrivate object.
  253. * REFGUID [in]: DirectSound device GUID.
  254. * DIRECTSOUNDBASICACCELERATION_LEVEL [in]: basic acceleration level.
  255. *
  256. * Returns:
  257. * HRESULT: DirectSound/COM result code.
  258. *
  259. ***************************************************************************/
  260. HRESULT PrvSetBasicAcceleration
  261. (
  262. LPKSPROPERTYSET pKsPropertySet,
  263. REFGUID guidDeviceId,
  264. DIRECTSOUNDBASICACCELERATION_LEVEL Level
  265. )
  266. {
  267. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION_DATA Data;
  268. HRESULT hr;
  269. Data.DeviceId = guidDeviceId;
  270. Data.Level = Level;
  271. hr =
  272. pKsPropertySet->Set
  273. (
  274. DSPROPSETID_DirectSoundBasicAcceleration,
  275. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION,
  276. NULL,
  277. 0,
  278. &Data,
  279. sizeof(Data)
  280. );
  281. return hr;
  282. }
  283. /***************************************************************************
  284. *
  285. * PrvGetDebugInformation
  286. *
  287. * Description:
  288. * Gets the current DirectSound debug settings.
  289. *
  290. * Arguments:
  291. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  292. * DirectSoundPrivate object.
  293. * LPDWORD [in]: receives DPF flags.
  294. * PULONG [out]: receives DPF level.
  295. * PULONG [out]: receives break level.
  296. * LPSTR [out]: receives log file name.
  297. *
  298. * Returns:
  299. * HRESULT: DirectSound/COM result code.
  300. *
  301. ***************************************************************************/
  302. HRESULT PrvGetDebugInformation
  303. (
  304. LPKSPROPERTYSET pKsPropertySet,
  305. LPDWORD pdwFlags,
  306. PULONG pulDpfLevel,
  307. PULONG pulBreakLevel,
  308. LPTSTR pszLogFile
  309. )
  310. {
  311. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO_DATA Data;
  312. HRESULT hr;
  313. hr =
  314. pKsPropertySet->Get
  315. (
  316. DSPROPSETID_DirectSoundDebug,
  317. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO,
  318. NULL,
  319. 0,
  320. &Data,
  321. sizeof(Data),
  322. NULL
  323. );
  324. if(SUCCEEDED(hr) && pdwFlags)
  325. {
  326. *pdwFlags = Data.Flags;
  327. }
  328. if(SUCCEEDED(hr) && pulDpfLevel)
  329. {
  330. *pulDpfLevel = Data.DpfLevel;
  331. }
  332. if(SUCCEEDED(hr) && pulBreakLevel)
  333. {
  334. *pulBreakLevel = Data.BreakLevel;
  335. }
  336. if(SUCCEEDED(hr) && pszLogFile)
  337. {
  338. lstrcpy
  339. (
  340. pszLogFile,
  341. Data.LogFile
  342. );
  343. }
  344. return hr;
  345. }