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
18 GetCatFileFromDriverPath(LPWSTR szFileName
, LPWSTR szCatFileName
)
20 GUID VerifyGuid
= DRIVER_ACTION_VERIFY
;
29 /* attempt to open file */
30 hFile
= CreateFileW(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
31 if (hFile
== INVALID_HANDLE_VALUE
)
34 /* calculate hash from file handle */
35 dwHash
= sizeof(bHash
);
36 if (!CryptCATAdminCalcHashFromFileHandle(hFile
, &dwHash
, bHash
, 0))
42 /* try open the CAT admin */
43 if (!CryptCATAdminAcquireContext(&hActAdmin
, &VerifyGuid
, 0))
49 /* search catalog to find for catalog containing this hash */
50 hCatInfo
= CryptCATAdminEnumCatalogFromHash(hActAdmin
, bHash
, dwHash
, 0, NULL
);
53 /* theres a catalog get the filename */
54 bRet
= CryptCATCatalogInfoFromContext(hCatInfo
, &CatInfo
, 0);
56 wcscpy(szCatFileName
, CatInfo
.wszCatalogFile
);
57 CryptCATAdminReleaseCatalogContext(hActAdmin
, hCatInfo
, 0);
62 CryptCATAdminReleaseContext(hActAdmin
, 0);
67 IsDriverWHQL(LPWSTR szFileName
)
69 WCHAR szCatFile
[MAX_PATH
];
73 /* get the driver's cat file */
74 if (!GetCatFileFromDriverPath(szFileName
, szCatFile
))
76 /* driver has no cat so its definately not WHQL signed */
80 /* open the CAT file */
81 hCat
= CryptCATOpen(szCatFile
, CRYPTCAT_OPEN_EXISTING
, 0, 0, 0);
82 if (hCat
== INVALID_HANDLE_VALUE
)
84 /* couldnt open cat */
89 * build certificate chain with CertGetCertificateChain
90 * verify certificate chain (WinVerifyTrust)
91 * retrieve signer (WTHelperGetProvSignerFromChain)
103 SetDeviceDetails(HWND hwndDlg
, LPCGUID classGUID
, LPCWSTR lpcstrDescription
)
107 SP_DEVINFO_DATA InfoData
;
110 WAVEOUTCAPSW waveOut
;
115 /* enumerate waveout devices */
116 numDev
= waveOutGetNumDevs();
121 ZeroMemory(&waveOut
, sizeof(waveOut
));
122 errCode
= waveOutGetDevCapsW(dwIndex
++, &waveOut
, sizeof(waveOut
));
123 if (!wcsncmp(lpcstrDescription
, waveOut
.szPname
, min(MAXPNAMELEN
, wcslen(waveOut
.szPname
))))
125 /* set the product id */
126 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_PRODUCTID
, waveOut
.wPid
, FALSE
);
127 /* set the vendor id */
128 SetDlgItemInt(hwndDlg
, IDC_STATIC_DSOUND_VENDORID
, waveOut
.wMid
, FALSE
);
129 /* check if its a wdm audio driver */
130 if (waveOut
.wPid
== MM_MSFT_WDMAUDIO_WAVEOUT
)
131 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_TYPE
, WM_SETTEXT
, 0, (LPARAM
)L
"WDM");
133 /* check if device is default device */
135 if (dwIndex
- 1 == 0) /* FIXME assume default playback device is device 0 */
136 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
138 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
140 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
141 /* set default device info */
142 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_STANDARD
, WM_SETTEXT
, 0, (LPARAM
)szText
);
145 }while(errCode
== MMSYSERR_NOERROR
&& dwIndex
< numDev
);
149 /* create the setup list */
150 hInfo
= SetupDiGetClassDevsW(classGUID
, NULL
, NULL
, DIGCF_PRESENT
|DIGCF_PROFILE
);
151 if (hInfo
== INVALID_HANDLE_VALUE
)
156 ZeroMemory(&InfoData
, sizeof(InfoData
));
157 InfoData
.cbSize
= sizeof(InfoData
);
159 if (SetupDiEnumDeviceInfo(hInfo
, dwIndex
, &InfoData
))
161 /* set device name */
162 if (SetupDiGetDeviceInstanceId(hInfo
, &InfoData
, szText
, sizeof(szText
)/sizeof(WCHAR
), NULL
))
163 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_DEVICEID
, WM_SETTEXT
, 0, (LPARAM
)szText
);
165 /* set the manufacturer name */
166 if (SetupDiGetDeviceRegistryPropertyW(hInfo
, &InfoData
, SPDRP_MFG
, NULL
, (PBYTE
)szText
, sizeof(szText
), NULL
))
167 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_PROVIDER
, WM_SETTEXT
, 0, (LPARAM
)szText
);
170 * we currently enumerate only the first adapter
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
);
179 if (GetLastError() == ERROR_NO_MORE_ITEMS
)
185 /* destroy the setup list */
186 SetupDiDestroyDeviceInfoList(hInfo
);
191 BOOL CALLBACK
DSEnumCallback(LPGUID lpGuid
, LPCWSTR lpcstrDescription
, LPCWSTR lpcstrModule
, LPVOID lpContext
)
193 PDXDIAG_CONTEXT pContext
= (PDXDIAG_CONTEXT
)lpContext
;
205 if (pContext
->NumSoundAdapter
)
206 hDlgs
= HeapReAlloc(GetProcessHeap(), 0, pContext
->hSoundWnd
, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
208 hDlgs
= HeapAlloc(GetProcessHeap(), 0, (pContext
->NumSoundAdapter
+ 1) * sizeof(HWND
));
213 pContext
->hSoundWnd
= hDlgs
;
214 hwndDlg
= CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_SOUND_DIALOG
), pContext
->hMainDialog
, SoundPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(hwndDlg
);
218 hResult
= DirectSoundCreate8(lpGuid
, (LPDIRECTSOUND8
*)&pObj
, NULL
);
219 if (hResult
== DS_OK
)
222 if (IDirectSound8_VerifyCertification(pObj
, &dwCertified
) == DS_OK
)
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_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
231 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
233 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
234 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_LOGO
, WM_SETTEXT
, 0, (LPARAM
)szText
);
235 IDirectSound8_Release(pObj
);
238 /* set device name */
239 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_DSOUND_NAME
, WM_SETTEXT
, 0, (LPARAM
)lpcstrDescription
);
241 /* set range for slider */
242 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETRANGE
, TRUE
, MAKELONG(0, 3));
244 /* FIXME set correct position */
245 SendDlgItemMessageW(hwndDlg
, IDC_SLIDER_DSOUND
, TBM_SETSEL
, FALSE
, 0);
247 /* set further device details */
248 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
)