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
16 GetCatFileFromDriverPath(LPWSTR szFileName
, LPWSTR szCatFileName
)
18 GUID VerifyGuid
= DRIVER_ACTION_VERIFY
;
27 /* attempt to open file */
28 hFile
= CreateFileW(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
29 if (hFile
== INVALID_HANDLE_VALUE
)
32 /* calculate hash from file handle */
33 dwHash
= sizeof(bHash
);
34 if (!CryptCATAdminCalcHashFromFileHandle(hFile
, &dwHash
, bHash
, 0))
40 /* try open the CAT admin */
41 if (!CryptCATAdminAcquireContext(&hActAdmin
, &VerifyGuid
, 0))
47 /* search catalog to find for catalog containing this hash */
48 hCatInfo
= CryptCATAdminEnumCatalogFromHash(hActAdmin
, bHash
, dwHash
, 0, NULL
);
51 /* theres a catalog get the filename */
52 bRet
= CryptCATCatalogInfoFromContext(hCatInfo
, &CatInfo
, 0);
54 wcscpy(szCatFileName
, CatInfo
.wszCatalogFile
);
55 CryptCATAdminReleaseCatalogContext(hActAdmin
, hCatInfo
, 0);
60 CryptCATAdminReleaseContext(hActAdmin
, 0);
65 IsDriverWHQL(LPWSTR szFileName
)
67 WCHAR szCatFile
[MAX_PATH
];
71 /* get the driver's cat file */
72 if (!GetCatFileFromDriverPath(szFileName
, szCatFile
))
74 /* driver has no cat so its definately not WHQL signed */
78 /* open the CAT file */
79 hCat
= CryptCATOpen(szCatFile
, CRYPTCAT_OPEN_EXISTING
, 0, 0, 0);
80 if (hCat
== INVALID_HANDLE_VALUE
)
82 /* couldnt open cat */
87 * build certificate chain with CertGetCertificateChain
88 * verify certificate chain (WinVerifyTrust)
89 * retrieve signer (WTHelperGetProvSignerFromChain)
101 SetDeviceDetails(HWND hwndDlg
, LPCGUID classGUID
, LPCWSTR lpcstrDescription
)
105 SP_DEVINFO_DATA InfoData
;
108 WAVEOUTCAPSW waveOut
;
113 /* enumerate waveout devices */
114 numDev
= waveOutGetNumDevs();
119 ZeroMemory(&waveOut
, sizeof(waveOut
));
120 errCode
= waveOutGetDevCapsW(dwIndex
++, &waveOut
, sizeof(waveOut
));
121 if (!wcsncmp(lpcstrDescription
, waveOut
.szPname
, min(MAXPNAMELEN
, wcslen(waveOut
.szPname
))))
123 /* set the product id */
124 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_PRODUCTID
, waveOut
.wPid
, FALSE
);
125 /* set the vendor id */
126 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_VENDORID
, waveOut
.wMid
, FALSE
);
127 /* check if its a wdm audio driver */
128 if (waveOut
.wPid
== MM_MSFT_WDMAUDIO_WAVEOUT
)
129 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_TYPE
, WM_SETTEXT
, 0, (LPARAM
)L
"WDM");
131 /* check if device is default device */
133 if (dwIndex
- 1 == 0) /* FIXME assume default playback device is device 0 */
134 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
136 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
138 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
139 /* set default device info */
140 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_STANDARD
, WM_SETTEXT
, 0, (LPARAM
)szText
);
143 }while(errCode
== MMSYSERR_NOERROR
&& dwIndex
< numDev
);
147 /* create the setup list */
148 hInfo
= SetupDiGetClassDevsW(classGUID
, NULL
, NULL
, DIGCF_PRESENT
|DIGCF_PROFILE
);
149 if (hInfo
== INVALID_HANDLE_VALUE
)
154 ZeroMemory(&InfoData
, sizeof(InfoData
));
155 InfoData
.cbSize
= sizeof(InfoData
);
157 if (SetupDiEnumDeviceInfo(hInfo
, dwIndex
, &InfoData
))
159 /* set device name */
160 if (SetupDiGetDeviceInstanceId(hInfo
, &InfoData
, szText
, sizeof(szText
)/sizeof(WCHAR
), NULL
))
161 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_DEVICEID
, WM_SETTEXT
, 0, (LPARAM
)szText
);
163 /* set the manufacturer name */
164 if (SetupDiGetDeviceRegistryPropertyW(hInfo
, &InfoData
, SPDRP_MFG
, NULL
, (PBYTE
)szText
, sizeof(szText
), NULL
))
165 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_PROVIDER
, WM_SETTEXT
, 0, (LPARAM
)szText
);
168 * we currently enumerate only the first adapter
170 hDlgCtrls
[0] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_DRIVER
);
171 hDlgCtrls
[1] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_VERSION
);
172 hDlgCtrls
[2] = GetDlgItem(hwndDlg
, IDC_STATIC_DSOUND_DATE
);
173 EnumerateDrivers(hDlgCtrls
, hInfo
, &InfoData
);
177 if (GetLastError() == ERROR_NO_MORE_ITEMS
)
183 /* destroy the setup list */
184 SetupDiDestroyDeviceInfoList(hInfo
);
189 BOOL CALLBACK
DSEnumCallback(LPGUID lpGuid
, LPCWSTR lpcstrDescription
, LPCWSTR lpcstrModule
, LPVOID lpContext
)
191 PDXDIAG_CONTEXT pContext
= (PDXDIAG_CONTEXT
)lpContext
;
203 if (pContext
->NumSoundAdapter
)
204 hDlgs
= HeapReAlloc(GetProcessHeap(), 0, pContext
->hSoundWnd
, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
206 hDlgs
= HeapAlloc(GetProcessHeap(), 0, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
211 pContext
->hSoundWnd
= hDlgs
;
212 hwndDlg
= CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_SOUND_DIALOG
), pContext
->hMainDialog
, SoundPageWndProc
, (LPARAM
)pContext
);
216 hResult
= DirectSoundCreate8(lpGuid
, (LPDIRECTSOUND8
*)&pObj
, NULL
);
217 if (hResult
== DS_OK
)
220 if (IDirectSound8_VerifyCertification(pObj
, &dwCertified
) == DS_OK
)
222 if (dwCertified
== DS_CERTIFIED
)
223 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
224 else if (dwCertified
== DS_UNCERTIFIED
)
225 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
229 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
231 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
232 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_LOGO
, WM_SETTEXT
, 0, (LPARAM
)szText
);
233 IDirectSound8_Release(pObj
);
236 /* set device name */
237 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_NAME
, WM_SETTEXT
, 0, (LPARAM
)lpcstrDescription
);
239 /* set range for slider */
240 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETRANGE
, TRUE
, MAKELONG(0, 3));
242 /* FIXME set correct position */
243 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETSEL
, FALSE
, 0);
245 /* set further device details */
246 SetDeviceDetails(hwndDlg
, &GUID_DEVCLASS_MEDIA
, lpcstrDescription
);
250 /* load sound resource string */
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
++;
265 void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext
)
270 /* create DSound object */
272 // if (hResult != DS_OK)
274 hResult
= DirectSoundEnumerateW(DSEnumCallback
, pContext
);
276 /* release the DSound object */
277 // pObj->lpVtbl->Release(pObj);
283 SoundPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
289 SetWindowPos(hDlg
, NULL
, 10, 32, 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
294 if (LOWORD(wParam
) == IDC_BUTTON_TESTDSOUND
)