push e9c4c6cdd0babd7b2cb4288f191bb331b756eaf2
[wine/hacks.git] / dlls / dxdiagn / provider.c
blobd3f0a26b7de5d9d036de502891a9da56ce7f5294
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004-2005 Raphael Junqueira
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #include "dxdiag_private.h"
27 #include "wine/unicode.h"
28 #include "winver.h"
29 #include "objidl.h"
30 #include "dshow.h"
31 #include "strmif.h"
32 #include "vfw.h"
33 #include "mmddk.h"
34 #include "ddraw.h"
35 #include "d3d9.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
41 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont);
43 /* IDxDiagProvider IUnknown parts follow: */
44 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
46 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
48 if (IsEqualGUID(riid, &IID_IUnknown)
49 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
50 IUnknown_AddRef(iface);
51 *ppobj = This;
52 return S_OK;
55 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
56 return E_NOINTERFACE;
59 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
60 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
61 ULONG refCount = InterlockedIncrement(&This->ref);
63 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
65 DXDIAGN_LockModule();
67 return refCount;
70 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
71 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
72 ULONG refCount = InterlockedDecrement(&This->ref);
74 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
76 if (!refCount) {
77 HeapFree(GetProcessHeap(), 0, This);
80 DXDIAGN_UnlockModule();
82 return refCount;
85 /* IDxDiagProvider Interface follow: */
86 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
87 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
88 TRACE("(%p,%p)\n", iface, pParams);
90 if (NULL == pParams) {
91 return E_POINTER;
93 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
94 return E_INVALIDARG;
97 This->init = TRUE;
98 memcpy(&This->params, pParams, pParams->dwSize);
99 return S_OK;
102 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
103 HRESULT hr = S_OK;
104 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
105 TRACE("(%p,%p)\n", iface, ppInstance);
107 if (NULL == ppInstance) {
108 return E_INVALIDARG;
110 if (FALSE == This->init) {
111 return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
113 if (NULL == This->pRootContainer) {
114 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
115 if (FAILED(hr)) {
116 return hr;
118 hr = DXDiag_InitRootDXDiagContainer(This->pRootContainer);
120 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
123 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
125 IDxDiagProviderImpl_QueryInterface,
126 IDxDiagProviderImpl_AddRef,
127 IDxDiagProviderImpl_Release,
128 IDxDiagProviderImpl_Initialize,
129 IDxDiagProviderImpl_GetRootContainer
132 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
133 IDxDiagProviderImpl* provider;
135 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
137 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
138 if (NULL == provider) {
139 *ppobj = NULL;
140 return E_OUTOFMEMORY;
142 provider->lpVtbl = &DxDiagProvider_Vtbl;
143 provider->ref = 0; /* will be inited with QueryInterface */
144 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
147 static inline HRESULT add_prop_str( IDxDiagContainer* cont, LPCWSTR prop, LPCWSTR str )
149 HRESULT hr;
150 VARIANT var;
152 V_VT( &var ) = VT_BSTR;
153 V_BSTR( &var ) = SysAllocString( str );
154 hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
155 VariantClear( &var );
157 return hr;
160 static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
162 VARIANT var;
164 V_VT( &var ) = VT_UI4;
165 V_UI4( &var ) = data;
166 return IDxDiagContainerImpl_AddProp( cont, prop, &var );
169 static inline HRESULT add_prop_bool( IDxDiagContainer* cont, LPCWSTR prop, BOOL data )
171 VARIANT var;
173 V_VT( &var ) = VT_BOOL;
174 V_BOOL( &var ) = data;
175 return IDxDiagContainerImpl_AddProp( cont, prop, &var );
178 static inline HRESULT add_prop_ull_as_str( IDxDiagContainer* cont, LPCWSTR prop, ULONGLONG data )
180 HRESULT hr;
181 VARIANT var;
183 V_VT( &var ) = VT_UI8;
184 V_UI8( &var ) = data;
185 VariantChangeType( &var, &var, 0, VT_BSTR );
186 hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
187 VariantClear( &var );
189 return hr;
192 static void get_display_device_id(WCHAR *szIdentifierBuffer)
194 static const WCHAR szNA[] = {'n','/','a',0};
196 HRESULT hr = E_FAIL;
198 HMODULE d3d9_handle;
199 IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
200 IDirect3D9 *pD3d = NULL;
201 D3DADAPTER_IDENTIFIER9 adapter_ident;
203 /* Retrieves the display device identifier from the d3d9 implementation. */
204 d3d9_handle = LoadLibraryA("d3d9.dll");
205 if(d3d9_handle)
206 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
207 if(pDirect3DCreate9)
208 pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
209 if(pD3d)
210 hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
211 if(SUCCEEDED(hr)) {
212 StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
213 } else {
214 memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
217 if (pD3d)
218 IDirect3D9_Release(pD3d);
219 if (d3d9_handle)
220 FreeLibrary(d3d9_handle);
224 * @param szFilePath: usually GetSystemDirectoryW
225 * @param szFileName: name of the dll without path
227 static HRESULT DXDiag_AddFileDescContainer(IDxDiagContainer* pSubCont, const WCHAR* szFilePath, const WCHAR* szFileName) {
228 HRESULT hr = S_OK;
229 /**/
230 static const WCHAR szSlashSep[] = {'\\',0};
231 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
232 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
233 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
234 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
235 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
236 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
237 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
238 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
239 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
240 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
241 /** values */
242 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
243 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
244 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
246 WCHAR szFile[512];
247 WCHAR szVersion_v[1024];
248 DWORD retval, hdl;
249 LPVOID pVersionInfo;
250 BOOL boolret;
251 UINT uiLength;
252 VS_FIXEDFILEINFO* pFileInfo;
254 TRACE("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
256 lstrcpyW(szFile, szFilePath);
257 lstrcatW(szFile, szSlashSep);
258 lstrcatW(szFile, szFileName);
260 retval = GetFileVersionInfoSizeW(szFile, &hdl);
261 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
262 boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
263 boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
265 add_prop_str(pSubCont, szPath, szFile);
266 add_prop_str(pSubCont, szName, szFileName);
267 add_prop_bool(pSubCont, bExists, boolret);
269 if (boolret) {
270 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
271 szVersionFormat,
272 HIWORD(pFileInfo->dwFileVersionMS),
273 LOWORD(pFileInfo->dwFileVersionMS),
274 HIWORD(pFileInfo->dwFileVersionLS),
275 LOWORD(pFileInfo->dwFileVersionLS));
277 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
279 add_prop_str(pSubCont, szVersion, szVersion_v);
280 add_prop_str(pSubCont, szAttributes, szFinal_Retail_v);
281 add_prop_str(pSubCont, szLanguageEnglish, szEnglish_v);
282 add_prop_ui4(pSubCont, dwFileTimeHigh, pFileInfo->dwFileDateMS);
283 add_prop_ui4(pSubCont, dwFileTimeLow, pFileInfo->dwFileDateLS);
284 add_prop_bool(pSubCont, bBeta, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE));
285 add_prop_bool(pSubCont, bDebug, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG));
288 HeapFree(GetProcessHeap(), 0, pVersionInfo);
290 return hr;
293 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
294 static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
295 static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
296 static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
297 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
298 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
299 static const WCHAR szDirectXVersionEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
300 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
301 static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
302 static const WCHAR szDirectXVersionLongEnglish_v[] = {'=',' ','"','D','i','r','e','c','t','X',' ','9','.','0','c',' ','(','4','.','0','9','.','0','0','0','0','.','0','9','0','4',')',0};
303 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
304 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
305 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
306 /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
307 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
308 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
309 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
310 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
311 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
312 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
313 MEMORYSTATUSEX msex;
314 OSVERSIONINFOW info;
315 WCHAR buffer[MAX_PATH];
317 add_prop_ui4(pSubCont, dwDirectXVersionMajor, 9);
318 add_prop_ui4(pSubCont, dwDirectXVersionMinor, 0);
319 add_prop_str(pSubCont, szDirectXVersionLetter, szDirectXVersionLetter_v);
320 add_prop_str(pSubCont, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
321 add_prop_str(pSubCont, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
322 add_prop_bool(pSubCont, bDebug, FALSE);
324 msex.dwLength = sizeof(msex);
325 GlobalMemoryStatusEx( &msex );
326 add_prop_ull_as_str(pSubCont, ullPhysicalMemory, msex.ullTotalPhys);
327 add_prop_ull_as_str(pSubCont, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
328 add_prop_ull_as_str(pSubCont, ullAvailPageFile, msex.ullAvailPageFile);
330 info.dwOSVersionInfoSize = sizeof(info);
331 GetVersionExW( &info );
332 add_prop_ui4(pSubCont, dwOSMajorVersion, info.dwMajorVersion);
333 add_prop_ui4(pSubCont, dwOSMinorVersion, info.dwMinorVersion);
334 add_prop_ui4(pSubCont, dwOSBuildNumber, info.dwBuildNumber);
335 add_prop_ui4(pSubCont, dwOSPlatformID, info.dwPlatformId);
336 add_prop_str(pSubCont, szCSDVersion, info.szCSDVersion);
338 GetWindowsDirectoryW(buffer, MAX_PATH);
339 add_prop_str(pSubCont, szWindowsDir, buffer);
341 return S_OK;
344 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
345 HRESULT hr = S_OK;
347 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
348 static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
350 static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
352 VARIANT v;
353 IDxDiagContainer* pDeviceSubCont = NULL;
354 IDxDiagContainer* pDriversCont = NULL;
356 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDeviceSubCont);
357 if (FAILED(hr)) { return hr; }
358 V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
359 hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
360 VariantClear(&v);
361 V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
362 hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
363 VariantClear(&v);
365 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
369 * Drivers Cont contains Files Desc Containers
372 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
373 if (FAILED(hr)) { return hr; }
374 hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
377 return hr;
380 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
381 HRESULT hr = S_OK;
383 static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
384 static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
385 static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
386 static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
387 static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
388 static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
389 static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
391 static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
393 VARIANT v;
394 IDxDiagContainer* pDiskSubCont = NULL;
395 IDxDiagContainer* pDriversCont = NULL;
397 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDiskSubCont);
398 if (FAILED(hr)) { return hr; }
399 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
403 * Drivers Cont contains Files Desc Containers
406 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
407 if (FAILED(hr)) { return hr; }
408 hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
410 return hr;
413 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont)
415 HRESULT hr = S_OK;
416 static const WCHAR dlls[][15] =
418 {'d','3','d','8','.','d','l','l',0},
419 {'d','3','d','9','.','d','l','l',0},
420 {'d','d','r','a','w','.','d','l','l',0},
421 {'d','e','v','e','n','u','m','.','d','l','l',0},
422 {'d','i','n','p','u','t','8','.','d','l','l',0},
423 {'d','i','n','p','u','t','.','d','l','l',0},
424 {'d','m','b','a','n','d','.','d','l','l',0},
425 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
426 {'d','m','i','m','e','.','d','l','l',0},
427 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
428 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
429 {'d','m','s','t','y','l','e','.','d','l','l',0},
430 {'d','m','s','y','n','t','h','.','d','l','l',0},
431 {'d','m','u','s','i','c','.','d','l','l',0},
432 {'d','p','l','a','y','x','.','d','l','l',0},
433 {'d','p','n','e','t','.','d','l','l',0},
434 {'d','s','o','u','n','d','.','d','l','l',0},
435 {'d','s','w','a','v','e','.','d','l','l',0},
436 {'d','x','d','i','a','g','n','.','d','l','l',0},
437 {'q','u','a','r','t','z','.','d','l','l',0}
439 WCHAR szFilePath[MAX_PATH];
440 INT i;
442 GetSystemDirectoryW(szFilePath, MAX_PATH);
444 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
446 static const WCHAR szFormat[] = {'%','d',0};
447 WCHAR szFileID[5];
448 IDxDiagContainer *pDXFileSubCont;
450 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
452 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDXFileSubCont);
453 if (FAILED(hr)) continue;
455 if (FAILED(DXDiag_AddFileDescContainer(pDXFileSubCont, szFilePath, dlls[i])) ||
456 FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, szFileID, pDXFileSubCont)))
458 IUnknown_Release(pDXFileSubCont);
459 continue;
462 return hr;
465 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
467 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
468 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
469 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
470 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
471 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
472 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
473 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
474 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
475 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
476 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
477 static const WCHAR szDisplayMemoryLocalized[] = {'s','z','D','i','s','p','l','a','y','M','e','m','o','r','y','L','o','c','a','l','i','z','e','d',0};
478 static const WCHAR szDisplayMemoryEnglish[] = {'s','z','D','i','s','p','l','a','y','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
480 static const WCHAR szAdapterID[] = {'0',0};
481 static const WCHAR szEmpty[] = {0};
483 HRESULT hr;
484 IDxDiagContainer *pDisplayAdapterSubCont = NULL;
486 IDirectDraw7 *pDirectDraw;
487 DDSCAPS2 dd_caps;
488 DISPLAY_DEVICEW disp_dev;
489 DDSURFACEDESC2 surface_descr;
490 DWORD tmp;
491 WCHAR buffer[256];
493 hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
494 if (FAILED( hr )) return hr;
495 hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
496 if (FAILED( hr )) return hr;
498 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
500 add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
501 add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
504 hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
505 if (FAILED( hr )) return hr;
507 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
508 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
509 hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
510 if (SUCCEEDED(hr))
512 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
514 snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
515 add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
516 add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
519 surface_descr.dwSize = sizeof(surface_descr);
520 hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
521 if (SUCCEEDED(hr))
523 if (surface_descr.dwFlags & DDSD_WIDTH)
524 add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
525 if (surface_descr.dwFlags & DDSD_HEIGHT)
526 add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
527 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
528 add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
531 get_display_device_id( buffer );
532 add_prop_str( pDisplayAdapterSubCont, szDeviceIdentifier, buffer );
534 add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
535 add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
536 add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
537 add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
539 IUnknown_Release( pDirectDraw );
540 return hr;
543 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
544 HRESULT hr = S_OK;
545 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
546 static const WCHAR DxDiag_SoundCaptureDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','C','a','p','t','u','r','e','D','e','v','i','c','e','s',0};
547 IDxDiagContainer* pSubSubCont = NULL;
549 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
550 if (FAILED(hr)) { return hr; }
551 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
553 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
554 if (FAILED(hr)) { return hr; }
555 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
557 return hr;
560 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
561 HRESULT hr = S_OK;
562 return hr;
565 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
566 HRESULT hr = S_OK;
567 return hr;
570 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
571 HRESULT hr = S_OK;
572 return hr;
575 struct REG_RF {
576 DWORD dwVersion;
577 DWORD dwMerit;
578 DWORD dwPins;
579 DWORD dwUnused;
581 struct REG_RFP {
582 BYTE signature[4]; /* e.g. "0pi3" */
583 DWORD dwFlags;
584 DWORD dwInstances;
585 DWORD dwMediaTypes;
586 DWORD dwMediums;
587 DWORD bCategory; /* is there a category clsid? */
588 /* optional: dwOffsetCategoryClsid */
590 struct REG_TYPE {
591 BYTE signature[4]; /* e.g. "0ty3" */
592 DWORD dwUnused;
593 DWORD dwOffsetMajor;
594 DWORD dwOffsetMinor;
597 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
598 HRESULT hr = S_OK;
599 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
600 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
601 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
602 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
603 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
604 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
605 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
606 static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0};
608 static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
609 static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
611 VARIANT v;
613 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
614 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
615 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
617 static const WCHAR szVersionFormat[] = {'v','%','d',0};
618 static const WCHAR szIdFormat[] = {'%','d',0};
619 int i = 0;
622 ICreateDevEnum* pCreateDevEnum = NULL;
623 IEnumMoniker* pEmCat = NULL;
624 IMoniker* pMCat = NULL;
625 /** */
626 hr = CoCreateInstance(&CLSID_SystemDeviceEnum,
627 NULL,
628 CLSCTX_INPROC_SERVER,
629 &IID_ICreateDevEnum,
630 (void**) &pCreateDevEnum);
631 if (FAILED(hr)) return hr;
633 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
634 if (FAILED(hr)) goto out_show_filters;
636 VariantInit(&v);
638 while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
639 IPropertyBag* pPropBag = NULL;
640 CLSID clsidCat;
641 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
642 if (SUCCEEDED(hr)) {
643 WCHAR* wszCatName = NULL;
644 WCHAR* wszCatClsid = NULL;
646 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
647 wszCatName = SysAllocString(V_BSTR(&v));
648 VariantClear(&v);
650 hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
651 wszCatClsid = SysAllocString(V_BSTR(&v));
652 hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
653 VariantClear(&v);
656 hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
657 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
658 VariantClear(&v);
661 if (SUCCEEDED(hr)) {
662 IEnumMoniker* pEnum = NULL;
663 IMoniker* pMoniker = NULL;
664 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
665 TRACE("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
666 if (FAILED(hr) || pEnum == NULL) {
667 goto class_enum_failed;
669 while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {
670 IPropertyBag* pPropFilterBag = NULL;
671 TRACE("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
672 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
673 if (SUCCEEDED(hr)) {
674 LPBYTE pData = NULL;
675 LPBYTE pCurrent = NULL;
676 struct REG_RF* prrf = NULL;
677 DWORD it;
678 DWORD dwNOutputs = 0;
679 DWORD dwNInputs = 0;
680 WCHAR bufferW[10];
681 IDxDiagContainer *pDShowSubCont = NULL;
683 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
684 if (FAILED(DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDShowSubCont)) ||
685 FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, bufferW, pDShowSubCont)))
687 IPropertyBag_Release(pPropFilterBag);
688 if (pDShowSubCont) IUnknown_Release(pDShowSubCont);
689 continue;
692 hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
693 hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, szName, &v);
694 TRACE("\tName:%s\n", debugstr_w(V_BSTR(&v)));
695 VariantClear(&v);
697 hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
698 TRACE("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
699 hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, ClsidFilterW, &v);
700 VariantClear(&v);
702 add_prop_str(pDShowSubCont, szCatName, wszCatName);
703 add_prop_str(pDShowSubCont, ClsidCatW, wszCatClsid);
705 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
706 hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData);
707 prrf = (struct REG_RF*) pData;
708 pCurrent = pData;
710 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, prrf->dwVersion);
711 add_prop_str(pDShowSubCont, szVersionW, bufferW);
713 pCurrent += sizeof(struct REG_RF);
714 for (it = 0; it < prrf->dwPins; ++it) {
715 struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent;
716 UINT j;
718 if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs;
719 else ++dwNInputs;
721 pCurrent += sizeof(struct REG_RFP);
722 if (prrfp->bCategory) {
723 pCurrent += sizeof(DWORD);
725 for (j = 0; j < prrfp->dwMediaTypes; ++j) {
726 struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent;
727 pCurrent += sizeof(*prt);
729 for (j = 0; j < prrfp->dwMediums; ++j) {
730 DWORD dwOffset = *(DWORD*) pCurrent;
731 pCurrent += sizeof(dwOffset);
735 add_prop_ui4(pDShowSubCont, dwInputs, dwNInputs);
736 add_prop_ui4(pDShowSubCont, dwOutputs, dwNOutputs);
737 add_prop_ui4(pDShowSubCont, dwMerit, prrf->dwMerit);
739 SafeArrayUnaccessData(V_UNION(&v, parray));
740 VariantClear(&v);
741 i++;
743 IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
745 IEnumMoniker_Release(pEnum); pEnum = NULL;
747 class_enum_failed:
748 SysFreeString(wszCatName);
749 SysFreeString(wszCatClsid);
750 IPropertyBag_Release(pPropBag); pPropBag = NULL;
752 IEnumMoniker_Release(pMCat); pMCat = NULL;
755 out_show_filters:
756 if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; }
757 if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; }
758 return hr;
761 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
762 HRESULT hr = S_OK;
763 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
764 static const WCHAR DxDiag_SystemDevices[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','D','e','v','i','c','e','s',0};
765 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
766 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
767 static const WCHAR DxDiag_DisplayDevices[] = {'D','x','D','i','a','g','_','D','i','s','p','l','a','y','D','e','v','i','c','e','s',0};
768 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
769 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
770 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
771 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
772 static const WCHAR DxDiag_DirectShowFilters[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','h','o','w','F','i','l','t','e','r','s',0};
773 IDxDiagContainer* pSubCont = NULL;
775 TRACE("(%p)\n", pRootCont);
777 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
778 if (FAILED(hr)) { return hr; }
779 hr = DXDiag_InitDXDiagSystemInfoContainer(pSubCont);
780 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
782 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
783 if (FAILED(hr)) { return hr; }
784 hr = DXDiag_InitDXDiagSystemDevicesContainer(pSubCont);
785 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemDevices, pSubCont);
787 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
788 if (FAILED(hr)) { return hr; }
789 hr = DXDiag_InitDXDiagLogicalDisksContainer(pSubCont);
790 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_LogicalDisks, pSubCont);
792 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
793 if (FAILED(hr)) { return hr; }
794 hr = DXDiag_InitDXDiagDirectXFilesContainer(pSubCont);
795 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectXFiles, pSubCont);
797 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
798 if (FAILED(hr)) { return hr; }
799 hr = DXDiag_InitDXDiagDisplayContainer(pSubCont);
800 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DisplayDevices, pSubCont);
802 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
803 if (FAILED(hr)) { return hr; }
804 hr = DXDiag_InitDXDiagDirectSoundContainer(pSubCont);
805 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectSound, pSubCont);
807 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
808 if (FAILED(hr)) { return hr; }
809 hr = DXDiag_InitDXDiagDirectMusicContainer(pSubCont);
810 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectMusic, pSubCont);
812 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
813 if (FAILED(hr)) { return hr; }
814 hr = DXDiag_InitDXDiagDirectInputContainer(pSubCont);
815 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectInput, pSubCont);
817 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
818 if (FAILED(hr)) { return hr; }
819 hr = DXDiag_InitDXDiagDirectPlayContainer(pSubCont);
820 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectPlay, pSubCont);
822 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
823 if (FAILED(hr)) { return hr; }
824 hr = DXDiag_InitDXDiagDirectShowFiltersContainer(pSubCont);
825 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectShowFilters, pSubCont);
827 return hr;