ReactOS  0.4.12-dev-102-g4b7f1e0
sound.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactX Diagnosis Application
3  * LICENSE: LGPL - See COPYING in the top level directory
4  * FILE: base/applications/dxdiag/sound.c
5  * PURPOSE: ReactX diagnosis sound page
6  * COPYRIGHT: Copyright 2008 Johannes Anderwald
7  *
8  */
9 
10 #include "precomp.h"
11 
12 #include <mmsystem.h>
13 #include <mmreg.h>
14 #include <dsound.h>
15 
16 #if 0
17 BOOL
18 GetCatFileFromDriverPath(LPWSTR szFileName, LPWSTR szCatFileName)
19 {
20  GUID VerifyGuid = DRIVER_ACTION_VERIFY;
21  HANDLE hFile;
22  DWORD dwHash;
23  BYTE bHash[100];
24  HCATINFO hCatInfo;
25  HCATADMIN hActAdmin;
26  BOOL bRet = FALSE;
27  CATALOG_INFO CatInfo;
28 
29  /* attempt to open file */
31  if (hFile == INVALID_HANDLE_VALUE)
32  return FALSE;
33 
34  /* calculate hash from file handle */
35  dwHash = sizeof(bHash);
36  if (!CryptCATAdminCalcHashFromFileHandle(hFile, &dwHash, bHash, 0))
37  {
38  CloseHandle(hFile);
39  return FALSE;
40  }
41 
42  /* try open the CAT admin */
43  if (!CryptCATAdminAcquireContext(&hActAdmin, &VerifyGuid, 0))
44  {
45  CloseHandle(hFile);
46  return FALSE;
47  }
48 
49  /* search catalog to find for catalog containing this hash */
50  hCatInfo = CryptCATAdminEnumCatalogFromHash(hActAdmin, bHash, dwHash, 0, NULL);
51  if (hCatInfo != NULL)
52  {
53  /* theres a catalog get the filename */
54  bRet = CryptCATCatalogInfoFromContext(hCatInfo, &CatInfo, 0);
55  if (bRet)
56  wcscpy(szCatFileName, CatInfo.wszCatalogFile);
57  CryptCATAdminReleaseCatalogContext(hActAdmin, hCatInfo, 0);
58  }
59 
60  /* perform cleanup */
61  CloseHandle(hFile);
62  CryptCATAdminReleaseContext(hActAdmin, 0);
63  return bRet;
64 }
65 
66 BOOL
67 IsDriverWHQL(LPWSTR szFileName)
68 {
69  WCHAR szCatFile[MAX_PATH];
70  HANDLE hCat;
71  BOOL bRet = FALSE;
72 
73  /* get the driver's cat file */
74  if (!GetCatFileFromDriverPath(szFileName, szCatFile))
75  {
76  /* driver has no cat so it's definitely not WHQL signed */
77  return FALSE;
78  }
79 
80  /* open the CAT file */
81  hCat = CryptCATOpen(szCatFile, CRYPTCAT_OPEN_EXISTING, 0, 0, 0);
82  if (hCat == INVALID_HANDLE_VALUE)
83  {
84  /* couldnt open cat */
85  return FALSE;
86  }
87 
88  /* FIXME
89  * build certificate chain with CertGetCertificateChain
90  * verify certificate chain (WinVerifyTrust)
91  * retrieve signer (WTHelperGetProvSignerFromChain)
92  */
93 
94 
95  /* close CAT file */
96  CryptCATClose(hCat);
97  return bRet;
98 }
99 #endif
100 
101 static
102 void
103 SetDeviceDetails(HWND hwndDlg, LPCGUID classGUID, LPCWSTR lpcstrDescription)
104 {
105  HDEVINFO hInfo;
106  DWORD dwIndex = 0;
107  SP_DEVINFO_DATA InfoData;
108  WCHAR szText[30];
109  HWND hDlgCtrls[3];
110  WAVEOUTCAPSW waveOut;
111  UINT numDev;
112  MMRESULT errCode;
113 
114 
115  /* enumerate waveout devices */
116  numDev = waveOutGetNumDevs();
117  if (numDev)
118  {
119  do
120  {
121  ZeroMemory(&waveOut, sizeof(waveOut));
122  errCode = waveOutGetDevCapsW(dwIndex++, &waveOut, sizeof(waveOut));
123  if (!wcsncmp(lpcstrDescription, waveOut.szPname, min(MAXPNAMELEN, wcslen(waveOut.szPname))))
124  {
125  /* set the product id */
127  /* set the vendor id */
129  /* check if it's a WDM audio driver */
130  if (waveOut.wPid == MM_MSFT_WDMAUDIO_WAVEOUT)
132 
133  /* check if device is default device */
134  szText[0] = L'\0';
135  if (dwIndex - 1 == 0) /* FIXME assume default playback device is device 0 */
136  LoadStringW(hInst, IDS_OPTION_YES, szText, sizeof(szText)/sizeof(WCHAR));
137  else
138  LoadStringW(hInst, IDS_OPTION_NO, szText, sizeof(szText)/sizeof(WCHAR));
139 
140  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
141  /* set default device info */
143  break;
144  }
145  }while(errCode == MMSYSERR_NOERROR && dwIndex < numDev);
146  }
147 
148  dwIndex = 0;
149  /* create the setup list */
151  if (hInfo == INVALID_HANDLE_VALUE)
152  return;
153 
154  do
155  {
156  ZeroMemory(&InfoData, sizeof(InfoData));
157  InfoData.cbSize = sizeof(InfoData);
158 
159  if (SetupDiEnumDeviceInfo(hInfo, dwIndex, &InfoData))
160  {
161  /* set device name */
162  if (SetupDiGetDeviceInstanceId(hInfo, &InfoData, szText, sizeof(szText)/sizeof(WCHAR), NULL))
164 
165  /* set the manufacturer name */
166  if (SetupDiGetDeviceRegistryPropertyW(hInfo, &InfoData, SPDRP_MFG, NULL, (PBYTE)szText, sizeof(szText), NULL))
168 
169  /* FIXME
170  * we currently enumerate only the first adapter
171  */
172  hDlgCtrls[0] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_DRIVER);
173  hDlgCtrls[1] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_VERSION);
174  hDlgCtrls[2] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_DATE);
175  EnumerateDrivers(hDlgCtrls, hInfo, &InfoData);
176  break;
177  }
178 
180  break;
181 
182  dwIndex++;
183  }while(TRUE);
184 
185  /* destroy the setup list */
187 }
188 
189 
190 
191 BOOL CALLBACK DSEnumCallback(LPGUID lpGuid, LPCWSTR lpcstrDescription, LPCWSTR lpcstrModule, LPVOID lpContext)
192 {
193  PDXDIAG_CONTEXT pContext = (PDXDIAG_CONTEXT)lpContext;
194  HWND * hDlgs;
195  HWND hwndDlg;
196  WCHAR szSound[20];
197  WCHAR szText[30];
198  IDirectSound8 *pObj;
199  HRESULT hResult;
200  DWORD dwCertified;
201 
202  if (!lpGuid)
203  return TRUE;
204 
205  if (pContext->NumSoundAdapter)
206  hDlgs = HeapReAlloc(GetProcessHeap(), 0, pContext->hSoundWnd, (pContext->NumSoundAdapter + 1) * sizeof(HWND));
207  else
208  hDlgs = HeapAlloc(GetProcessHeap(), 0, (pContext->NumSoundAdapter + 1) * sizeof(HWND));
209 
210  if (!hDlgs)
211  return FALSE;
212 
213  pContext->hSoundWnd = hDlgs;
215  if (!hwndDlg)
216  return FALSE;
217 
218  hResult = DirectSoundCreate8(lpGuid, (LPDIRECTSOUND8*)&pObj, NULL);
219  if (hResult == DS_OK)
220  {
221  szText[0] = L'\0';
222  if (IDirectSound8_VerifyCertification(pObj, &dwCertified) == DS_OK)
223  {
224  if (dwCertified == DS_CERTIFIED)
225  LoadStringW(hInst, IDS_OPTION_YES, szText, sizeof(szText)/sizeof(WCHAR));
226  else if (dwCertified == DS_UNCERTIFIED)
227  LoadStringW(hInst, IDS_NOT_APPLICABLE, szText, sizeof(szText)/sizeof(WCHAR));
228  }
229  else
230  {
231  LoadStringW(hInst, IDS_OPTION_NO, szText, sizeof(szText)/sizeof(WCHAR));
232  }
233  szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
235  IDirectSound8_Release(pObj);
236  }
237 
238  /* set device name */
239  SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_NAME, WM_SETTEXT, 0, (LPARAM)lpcstrDescription);
240 
241  /* set range for slider */
243 
244  /* FIXME set correct position */
246 
247  /* set further device details */
248  SetDeviceDetails(hwndDlg, &GUID_DEVCLASS_MEDIA, lpcstrDescription);
249 
250  /* load sound resource string */
251  szSound[0] = L'\0';
252  LoadStringW(hInst, IDS_SOUND_DIALOG, szSound, sizeof(szSound)/sizeof(WCHAR));
253  szSound[(sizeof(szSound)/sizeof(WCHAR))-1] = L'\0';
254  /* output the device id */
255  wsprintfW (szText, L"%s %u", szSound, pContext->NumSoundAdapter + 1);
256  /* insert it into general tab */
257  InsertTabCtrlItem(pContext->hTabCtrl, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 1, szText);
258  /* store dialog window */
259  hDlgs[pContext->NumSoundAdapter] = hwndDlg;
260  pContext->NumSoundAdapter++;
261  return TRUE;
262 }
263 
264 
266 {
267  HRESULT hResult;
268 
269 
270  /* create DSound object */
271 
272 // if (hResult != DS_OK)
273 // return;
274  hResult = DirectSoundEnumerateW(DSEnumCallback, pContext);
275 
276  /* release the DSound object */
277 // pObj->lpVtbl->Release(pObj);
278  (void)hResult;
279 }
280 
281 
284 {
285  switch (message)
286  {
287  case WM_INITDIALOG:
288  {
290  return TRUE;
291  }
292  case WM_COMMAND:
293  {
294  if (LOWORD(wParam) == IDC_BUTTON_TESTDSOUND)
295  {
296  return FALSE;
297  }
298  break;
299  }
300  }
301 
302  return FALSE;
303 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1792
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID, LPDIRECTSOUND8 *ppDS, IUnknown *pUnkOuter)
Definition: directsound.c:504
BOOL WINAPI CryptCATAdminCalcHashFromFileHandle(HANDLE hFile, DWORD *pcbHash, BYTE *pbHash, DWORD dwFlags)
Definition: crypt.c:209
#define CloseHandle
Definition: compat.h:398
VOID InsertTabCtrlItem(HWND hDlgCtrl, INT Position, LPWSTR uId)
Definition: dxdiag.c:102
#define IDC_STATIC_ADAPTER_PROVIDER
Definition: resource.h:76
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
#define SPDRP_MFG
Definition: setupapi.h:513
#define IDC_STATIC_DSOUND_PRODUCTID
Definition: resource.h:68
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDD_SOUND_DIALOG
Definition: resource.h:9
static void SetDeviceDetails(HWND hwndDlg, LPCGUID classGUID, LPCWSTR lpcstrDescription)
Definition: sound.c:103
#define CALLBACK
Definition: compat.h:27
#define TBM_SETRANGE
Definition: commctrl.h:2007
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize)
Definition: devinst.c:3229
BOOL CALLBACK DSEnumCallback(LPGUID lpGuid, LPCWSTR lpcstrDescription, LPCWSTR lpcstrModule, LPVOID lpContext)
Definition: sound.c:191
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
UINT MMRESULT
Definition: mmsystem.h:962
#define SWP_NOZORDER
Definition: winuser.h:1232
#define IDC_STATIC_DSOUND_LOGO
Definition: resource.h:74
int32_t INT_PTR
Definition: typedefs.h:62
#define IDirectSound8_Release(p)
Definition: dsound.h:507
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDC_BUTTON_TESTDSOUND
Definition: resource.h:78
#define IDC_STATIC_DSOUND_STANDARD
Definition: resource.h:70
UINT_PTR WPARAM
Definition: windef.h:207
#define IDS_NOT_APPLICABLE
Definition: resource.h:125
#define DS_CERTIFIED
Definition: dsound.h:326
#define IDC_STATIC_DSOUND_VENDORID
Definition: resource.h:67
#define IDS_SOUND_DIALOG
Definition: resource.h:106
BOOL WINAPI CryptCATClose(HANDLE hCatalog)
Definition: crypt.c:530
UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2176
static const WCHAR szText[]
Definition: dialog.c:139
#define IDC_STATIC_DSOUND_DATE
Definition: resource.h:73
BOOL WINAPI CryptCATAdminReleaseContext(HCATADMIN hCatAdmin, DWORD dwFlags)
Definition: crypt.c:434
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKELONG(a, b)
Definition: typedefs.h:248
BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN *catAdmin, const GUID *sys, DWORD dwFlags)
Definition: crypt.c:98
smooth NULL
Definition: ftsmooth.c:416
struct DXDIAG_CONTEXT * PDXDIAG_CONTEXT
#define MM_MSFT_WDMAUDIO_WAVEOUT
Definition: mmreg.h:35
#define TBM_SETSEL
Definition: commctrl.h:2011
#define IDC_STATIC_DSOUND_NAME
Definition: resource.h:65
UINT WINAPI waveOutGetNumDevs(void)
Definition: winmm.c:2140
#define WM_SETTEXT
Definition: winuser.h:1599
#define OPEN_EXISTING
Definition: compat.h:426
#define DS_OK
Definition: dsound.h:116
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin, HCATINFO hCatInfo, DWORD dwFlags)
Definition: crypt.c:402
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LONG HRESULT
Definition: typedefs.h:77
#define SWP_NOACTIVATE
Definition: winuser.h:1227
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:26
#define IDC_STATIC_DSOUND_DEVICEID
Definition: resource.h:66
unsigned int UINT
Definition: ndis.h:50
#define IDS_OPTION_YES
Definition: resource.h:126
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_OPTION_NO
Definition: resource.h:152
HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:210
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define DS_UNCERTIFIED
Definition: dsound.h:327
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
WCHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1039
#define IDC_STATIC_DSOUND_TYPE
Definition: resource.h:69
#define CRYPTCAT_OPEN_EXISTING
Definition: mscat.h:33
HWND * hSoundWnd
Definition: precomp.h:36
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
static const WCHAR L[]
Definition: oid.c:1087
#define SetupDiGetDeviceInstanceId
Definition: setupapi.h:2594
struct IDirectSound8 * LPDIRECTSOUND8
Definition: dsound.h:73
unsigned char BYTE
Definition: mem.h:68
#define GENERIC_READ
Definition: compat.h:124
#define WM_COMMAND
Definition: winuser.h:1716
#define IDC_STATIC_DSOUND_VERSION
Definition: resource.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL GetCatFileFromDriverPath(LPWSTR szFileName, LPWSTR szCatFileName)
#define DRIVER_ACTION_VERIFY
Definition: softpub.h:200
#define SWP_NOSIZE
Definition: winuser.h:1230
#define IDC_STATIC_DSOUND_DRIVER
Definition: resource.h:71
ULONG NumSoundAdapter
Definition: precomp.h:35
HINSTANCE hInst
Definition: dxdiag.c:13
#define IDC_SLIDER_DSOUND
Definition: resource.h:77
WCHAR wszCatalogFile[MAX_PATH]
Definition: mscat.h:87
BOOL WINAPI CryptCATCatalogInfoFromContext(HCATINFO hcatinfo, CATALOG_INFO *info, DWORD flags)
Definition: crypt.c:825
#define HeapReAlloc
Definition: compat.h:393
#define min(a, b)
Definition: monoChain.cc:55
VOID EnumerateDrivers(PVOID Context, HDEVINFO hList, PSP_DEVINFO_DATA pInfoData)
Definition: display.c:103
#define DIGCF_PROFILE
Definition: setupapi.h:173
void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext)
Definition: sound.c:265
#define MAXPNAMELEN
Definition: mmsystem.h:24
#define CreateFileW
Definition: compat.h:400
HWND hMainDialog
Definition: precomp.h:31
HWND WINAPI CreateDialogParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define IDirectSound8_VerifyCertification(p, a)
Definition: dsound.h:518
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66
#define WM_INITDIALOG
Definition: winuser.h:1715
BOOL EnableDialogTheme(HWND hwnd)
Definition: dxdiag.c:38
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
HANDLE WINAPI CryptCATOpen(LPWSTR pwszFileName, DWORD fdwOpenFlags, HCRYPTPROV hProv, DWORD dwPublicVersion, DWORD dwEncodingType)
Definition: crypt.c:844
HCATINFO WINAPI CryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, BYTE *pbHash, DWORD cbHash, DWORD dwFlags, HCATINFO *phPrevCatInfo)
Definition: crypt.c:270
#define DIGCF_PRESENT
Definition: setupapi.h:171
INT_PTR CALLBACK SoundPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: sound.c:283
#define SWP_NOOWNERZORDER
Definition: winuser.h:1234