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
15 GetCatFileFromDriverPath(LPWSTR szFileName
, LPWSTR szCatFileName
)
17 GUID VerifyGuid
= DRIVER_ACTION_VERIFY
;
26 /* attempt to open file */
27 hFile
= CreateFileW(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
28 if (hFile
== INVALID_HANDLE_VALUE
)
31 /* calculate hash from file handle */
32 dwHash
= sizeof(bHash
);
33 if (!CryptCATAdminCalcHashFromFileHandle(hFile
, &dwHash
, bHash
, 0))
39 /* try open the CAT admin */
40 if (!CryptCATAdminAcquireContext(&hActAdmin
, &VerifyGuid
, 0))
46 /* search catalog to find for catalog containing this hash */
47 hCatInfo
= CryptCATAdminEnumCatalogFromHash(hActAdmin
, bHash
, dwHash
, 0, NULL
);
50 /* theres a catalog get the filename */
51 bRet
= CryptCATCatalogInfoFromContext(hCatInfo
, &CatInfo
, 0);
53 wcscpy(szCatFileName
, CatInfo
.wszCatalogFile
);
54 CryptCATAdminReleaseCatalogContext(hActAdmin
, hCatInfo
, 0);
59 CryptCATAdminReleaseContext(hActAdmin
, 0);
64 IsDriverWHQL(LPWSTR szFileName
)
66 WCHAR szCatFile
[MAX_PATH
];
70 /* get the driver's cat file */
71 if (!GetCatFileFromDriverPath(szFileName
, szCatFile
))
73 /* driver has no cat so its definately not WHQL signed */
77 /* open the CAT file */
78 hCat
= CryptCATOpen(szCatFile
, CRYPTCAT_OPEN_EXISTING
, 0, 0, 0);
79 if (hCat
== INVALID_HANDLE_VALUE
)
81 /* couldnt open cat */
86 * build certificate chain with CertGetCertificateChain
87 * verify certificate chain (WinVerifyTrust)
88 * retrieve signer (WTHelperGetProvSignerFromChain)
100 SetDeviceDetails(HWND hwndDlg
, LPCGUID classGUID
, LPCWSTR lpcstrDescription
)
104 SP_DEVINFO_DATA InfoData
;
107 WAVEOUTCAPSW waveOut
;
112 /* enumerate waveout devices */
113 numDev
= waveOutGetNumDevs();
118 ZeroMemory(&waveOut
, sizeof(waveOut
));
119 errCode
= waveOutGetDevCapsW(dwIndex
++, &waveOut
, sizeof(waveOut
));
120 if (!wcsncmp(lpcstrDescription
, waveOut
.szPname
, min(MAXPNAMELEN
, wcslen(waveOut
.szPname
))))
122 /* set the product id */
123 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_PRODUCTID
, waveOut
.wPid
, FALSE
);
124 /* set the vendor id */
125 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_VENDORID
, waveOut
.wMid
, FALSE
);
126 /* check if its a wdm audio driver */
127 if (waveOut
.wPid
== MM_MSFT_WDMAUDIO_WAVEOUT
)
128 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_TYPE
, WM_SETTEXT
, 0, (LPARAM
)L
"WDM");
130 /* check if device is default device */
132 if (dwIndex
- 1 == 0) /* FIXME assume default playback device is device 0 */
133 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
135 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
137 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
138 /* set default device info */
139 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_STANDARD
, WM_SETTEXT
, 0, (LPARAM
)szText
);
142 }while(errCode
== MMSYSERR_NOERROR
&& dwIndex
< numDev
);
146 /* create the setup list */
147 hInfo
= SetupDiGetClassDevsW(classGUID
, NULL
, NULL
, DIGCF_PRESENT
|DIGCF_PROFILE
);
148 if (hInfo
== INVALID_HANDLE_VALUE
)
153 ZeroMemory(&InfoData
, sizeof(InfoData
));
154 InfoData
.cbSize
= sizeof(InfoData
);
156 if (SetupDiEnumDeviceInfo(hInfo
, dwIndex
, &InfoData
))
158 /* set device name */
159 if (SetupDiGetDeviceInstanceId(hInfo
, &InfoData
, szText
, sizeof(szText
)/sizeof(WCHAR
), NULL
))
160 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_DEVICEID
, WM_SETTEXT
, 0, (LPARAM
)szText
);
162 /* set the manufacturer name */
163 if (SetupDiGetDeviceRegistryPropertyW(hInfo
, &InfoData
, SPDRP_MFG
, NULL
, (PBYTE
)szText
, sizeof(szText
), NULL
))
164 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_PROVIDER
, WM_SETTEXT
, 0, (LPARAM
)szText
);
167 * we currently enumerate only the first adapter
169 hDlgCtrls
[0] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_DRIVER
);
170 hDlgCtrls
[1] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_VERSION
);
171 hDlgCtrls
[2] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_DATE
);
172 EnumerateDrivers(hDlgCtrls
, hInfo
, &InfoData
);
176 if (GetLastError() == ERROR_NO_MORE_ITEMS
)
182 /* destroy the setup list */
183 SetupDiDestroyDeviceInfoList(hInfo
);
188 BOOL CALLBACK
DSEnumCallback(LPGUID lpGuid
, LPCWSTR lpcstrDescription
, LPCWSTR lpcstrModule
, LPVOID lpContext
)
190 PDXDIAG_CONTEXT pContext
= (PDXDIAG_CONTEXT
)lpContext
;
202 if (pContext
->NumSoundAdapter
)
203 hDlgs
= HeapReAlloc(GetProcessHeap(), 0, pContext
->hSoundWnd
, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
205 hDlgs
= HeapAlloc(GetProcessHeap(), 0, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
210 pContext
->hSoundWnd
= hDlgs
;
211 hwndDlg
= CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_SOUND_DIALOG
), pContext
->hMainDialog
, SoundPageWndProc
, (LPARAM
)pContext
);
215 hResult
= DirectSoundCreate8(lpGuid
, (LPDIRECTSOUND8
*)&pObj
, NULL
);
216 if (hResult
== DS_OK
)
219 if (IDirectSound8_VerifyCertification(pObj
, &dwCertified
) == DS_OK
)
221 if (dwCertified
== DS_CERTIFIED
)
222 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
223 else if (dwCertified
== DS_UNCERTIFIED
)
224 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
228 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
230 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
231 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_LOGO
, WM_SETTEXT
, 0, (LPARAM
)szText
);
232 IDirectSound8_Release(pObj
);
235 /* set device name */
236 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_NAME
, WM_SETTEXT
, 0, (LPARAM
)lpcstrDescription
);
238 /* set range for slider */
239 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETRANGE
, TRUE
, MAKELONG(0, 3));
241 /* FIXME set correct position */
242 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETSEL
, FALSE
, 0);
244 /* set further device details */
245 SetDeviceDetails(hwndDlg
, &GUID_DEVCLASS_MEDIA
, lpcstrDescription
);
249 /* load sound resource string */
251 LoadStringW(hInst
, IDS_SOUND_DIALOG
, szSound
, sizeof(szSound
)/sizeof(WCHAR
));
252 szSound
[(sizeof(szSound
)/sizeof(WCHAR
))-1] = L
'\0';
253 /* output the device id */
254 wsprintfW (szText
, L
"%s %u", szSound
, pContext
->NumSoundAdapter
+ 1);
255 /* insert it into general tab */
256 InsertTabCtrlItem(pContext
->hTabCtrl
, pContext
->NumDisplayAdapter
+ pContext
->NumSoundAdapter
+ 1, szText
);
257 /* store dialog window */
258 hDlgs
[pContext
->NumSoundAdapter
] = hwndDlg
;
259 pContext
->NumSoundAdapter
++;
264 void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext
)
269 /* create DSound object */
271 // if (hResult != DS_OK)
273 hResult
= DirectSoundEnumerateW(DSEnumCallback
, pContext
);
275 /* release the DSound object */
276 // pObj->lpVtbl->Release(pObj);
282 SoundPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
288 SetWindowPos(hDlg
, NULL
, 10, 32, 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
293 if (LOWORD(wParam
) == IDC_BUTTON_TESTDSOUND
)