mshtml/tests: Make sure return value is used (LLVM/Clang).
[wine] / dlls / dxdiagn / provider.c
1 /* 
2  * IDxDiagProvider Implementation
3  * 
4  * Copyright 2004-2005 Raphael Junqueira
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "config.h"
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "dxdiag_private.h"
28 #include "wine/unicode.h"
29 #include "winver.h"
30 #include "objidl.h"
31 #include "dshow.h"
32 #include "vfw.h"
33 #include "mmddk.h"
34 #include "ddraw.h"
35 #include "d3d9.h"
36 #include "strmif.h"
37 #include "initguid.h"
38 #include "fil_data.h"
39
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
43
44 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont);
45
46 /* IDxDiagProvider IUnknown parts follow: */
47 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
48 {
49     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
50
51     if (!ppobj) return E_INVALIDARG;
52
53     if (IsEqualGUID(riid, &IID_IUnknown)
54         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
55         IUnknown_AddRef(iface);
56         *ppobj = This;
57         return S_OK;
58     }
59
60     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
61     *ppobj = NULL;
62     return E_NOINTERFACE;
63 }
64
65 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
66     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
67     ULONG refCount = InterlockedIncrement(&This->ref);
68
69     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
70
71     DXDIAGN_LockModule();
72
73     return refCount;
74 }
75
76 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
77     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
78     ULONG refCount = InterlockedDecrement(&This->ref);
79
80     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
81
82     if (!refCount) {
83         HeapFree(GetProcessHeap(), 0, This);
84     }
85
86     DXDIAGN_UnlockModule();
87     
88     return refCount;
89 }
90
91 /* IDxDiagProvider Interface follow: */
92 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
93     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
94     TRACE("(%p,%p)\n", iface, pParams);
95
96     if (NULL == pParams) {
97       return E_POINTER;
98     }
99     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
100         pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
101       return E_INVALIDARG;
102     }
103
104     This->init = TRUE;
105     memcpy(&This->params, pParams, pParams->dwSize);
106     return S_OK;
107 }
108
109 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
110   HRESULT hr;
111   IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
112   IDxDiagContainer *root;
113
114   TRACE("(%p,%p)\n", iface, ppInstance);
115
116   if (FALSE == This->init) {
117     return CO_E_NOTINITIALIZED;
118   }
119
120   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void **)&root);
121   if (FAILED(hr)) {
122     return hr;
123   }
124
125   DXDiag_InitRootDXDiagContainer(root);
126
127   return IDxDiagContainerImpl_QueryInterface(root, &IID_IDxDiagContainer, (void **)ppInstance);
128 }
129
130 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
131 {
132     IDxDiagProviderImpl_QueryInterface,
133     IDxDiagProviderImpl_AddRef,
134     IDxDiagProviderImpl_Release,
135     IDxDiagProviderImpl_Initialize,
136     IDxDiagProviderImpl_GetRootContainer
137 };
138
139 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
140   IDxDiagProviderImpl* provider;
141
142   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
143
144   *ppobj = NULL;
145   if (punkOuter) return CLASS_E_NOAGGREGATION;
146
147   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
148   if (NULL == provider) return E_OUTOFMEMORY;
149   provider->lpVtbl = &DxDiagProvider_Vtbl;
150   provider->ref = 0; /* will be inited with QueryInterface */
151   return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
152
153
154 static inline HRESULT add_prop_str( IDxDiagContainer* cont, LPCWSTR prop, LPCWSTR str )
155 {
156     HRESULT hr;
157     VARIANT var;
158
159     V_VT( &var ) = VT_BSTR;
160     V_BSTR( &var ) = SysAllocString( str );
161     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
162     VariantClear( &var );
163
164     return hr;
165 }
166
167 static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
168 {
169     VARIANT var;
170
171     V_VT( &var ) = VT_UI4;
172     V_UI4( &var ) = data;
173     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
174 }
175
176 static inline HRESULT add_prop_bool( IDxDiagContainer* cont, LPCWSTR prop, BOOL data )
177 {
178     VARIANT var;
179
180     V_VT( &var ) = VT_BOOL;
181     V_BOOL( &var ) = data;
182     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
183 }
184
185 static inline HRESULT add_prop_ull_as_str( IDxDiagContainer* cont, LPCWSTR prop, ULONGLONG data )
186 {
187     HRESULT hr;
188     VARIANT var;
189
190     V_VT( &var ) = VT_UI8;
191     V_UI8( &var ) = data;
192     VariantChangeType( &var, &var, 0, VT_BSTR );
193     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
194     VariantClear( &var );
195
196     return hr;
197 }
198
199 static void get_display_device_id(WCHAR *szIdentifierBuffer)
200 {
201     static const WCHAR szNA[] = {'n','/','a',0};
202
203     HRESULT hr = E_FAIL;
204
205     HMODULE                 d3d9_handle;
206     IDirect3D9             *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
207     IDirect3D9             *pD3d = NULL;
208     D3DADAPTER_IDENTIFIER9  adapter_ident;
209
210     /* Retrieves the display device identifier from the d3d9 implementation. */
211     d3d9_handle = LoadLibraryA("d3d9.dll");
212     if(d3d9_handle)
213         pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
214     if(pDirect3DCreate9)
215         pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
216     if(pD3d)
217         hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
218     if(SUCCEEDED(hr)) {
219         StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
220     } else {
221         memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
222     }
223
224     if (pD3d)
225         IDirect3D9_Release(pD3d);
226     if (d3d9_handle)
227         FreeLibrary(d3d9_handle);
228 }
229
230 /**
231  * @param szFilePath: usually GetSystemDirectoryW
232  * @param szFileName: name of the dll without path
233  */
234 static HRESULT DXDiag_AddFileDescContainer(IDxDiagContainer* pSubCont, const WCHAR* szFilePath, const WCHAR* szFileName) {
235   HRESULT hr = S_OK;
236   /**/
237   static const WCHAR szSlashSep[] = {'\\',0};
238   static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
239   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
240   static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
241   static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
242   static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
243   static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
244   static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
245   static const WCHAR bBeta[] = {'b','B','e','t','a',0};
246   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
247   static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
248   /** values */
249   static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
250   static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
251   static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
252
253   WCHAR szFile[512];
254   WCHAR szVersion_v[1024];
255   DWORD retval, hdl;
256   LPVOID pVersionInfo;
257   BOOL boolret;
258   UINT uiLength;
259   VS_FIXEDFILEINFO* pFileInfo;
260
261   TRACE("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
262
263   lstrcpyW(szFile, szFilePath);
264   lstrcatW(szFile, szSlashSep);
265   lstrcatW(szFile, szFileName);
266
267   retval = GetFileVersionInfoSizeW(szFile, &hdl);
268   pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
269   boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
270   boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
271
272   add_prop_str(pSubCont, szPath, szFile);
273   add_prop_str(pSubCont, szName, szFileName);
274   add_prop_bool(pSubCont, bExists, boolret);
275
276   if (boolret) {
277     snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
278               szVersionFormat,
279               HIWORD(pFileInfo->dwFileVersionMS), 
280               LOWORD(pFileInfo->dwFileVersionMS),
281               HIWORD(pFileInfo->dwFileVersionLS),
282               LOWORD(pFileInfo->dwFileVersionLS));
283
284     TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
285
286     add_prop_str(pSubCont, szVersion,         szVersion_v);
287     add_prop_str(pSubCont, szAttributes,      szFinal_Retail_v);
288     add_prop_str(pSubCont, szLanguageEnglish, szEnglish_v);
289     add_prop_ui4(pSubCont, dwFileTimeHigh,    pFileInfo->dwFileDateMS);
290     add_prop_ui4(pSubCont, dwFileTimeLow,     pFileInfo->dwFileDateLS);
291     add_prop_bool(pSubCont, bBeta,  0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE));
292     add_prop_bool(pSubCont, bDebug, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG));
293   }
294
295   HeapFree(GetProcessHeap(), 0, pVersionInfo);
296
297   return hr;
298 }
299
300 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
301   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};
302   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};
303   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};
304   static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
305   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
306   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};
307   static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
308   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};
309   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};
310   static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
311   static const WCHAR ullUsedPageFile[]   = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
312   static const WCHAR ullAvailPageFile[]  = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
313   /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
314   static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
315   static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
316   static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
317   static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
318   static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
319   static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
320   MEMORYSTATUSEX msex;
321   OSVERSIONINFOW info;
322   WCHAR buffer[MAX_PATH];
323
324   add_prop_ui4(pSubCont, dwDirectXVersionMajor, 9);
325   add_prop_ui4(pSubCont, dwDirectXVersionMinor, 0);
326   add_prop_str(pSubCont, szDirectXVersionLetter, szDirectXVersionLetter_v);
327   add_prop_str(pSubCont, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
328   add_prop_str(pSubCont, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
329   add_prop_bool(pSubCont, bDebug, FALSE);
330
331   msex.dwLength = sizeof(msex);
332   GlobalMemoryStatusEx( &msex );
333   add_prop_ull_as_str(pSubCont, ullPhysicalMemory, msex.ullTotalPhys);
334   add_prop_ull_as_str(pSubCont, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
335   add_prop_ull_as_str(pSubCont, ullAvailPageFile, msex.ullAvailPageFile);
336
337   info.dwOSVersionInfoSize = sizeof(info);
338   GetVersionExW( &info );
339   add_prop_ui4(pSubCont, dwOSMajorVersion, info.dwMajorVersion);
340   add_prop_ui4(pSubCont, dwOSMinorVersion, info.dwMinorVersion);
341   add_prop_ui4(pSubCont, dwOSBuildNumber,  info.dwBuildNumber);
342   add_prop_ui4(pSubCont, dwOSPlatformID,   info.dwPlatformId);
343   add_prop_str(pSubCont, szCSDVersion,     info.szCSDVersion);
344
345   GetWindowsDirectoryW(buffer, MAX_PATH);
346   add_prop_str(pSubCont, szWindowsDir, buffer);
347
348   return S_OK;
349 }
350
351 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
352   HRESULT hr = S_OK;
353   /*
354   static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
355   static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
356
357   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
358
359   VARIANT v;
360   IDxDiagContainer* pDeviceSubCont = NULL;
361   IDxDiagContainer* pDriversCont = NULL;
362
363   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDeviceSubCont);
364   if (FAILED(hr)) { return hr; }
365   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
366   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
367   VariantClear(&v);
368   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
369   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
370   VariantClear(&v);
371
372   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
373   */
374
375   /*
376    * Drivers Cont contains Files Desc Containers
377    */
378   /*
379   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
380   if (FAILED(hr)) { return hr; }
381   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
382
383   */
384   return hr;
385 }
386
387 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
388   HRESULT hr = S_OK;
389   /*
390   static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
391   static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
392   static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
393   static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
394   static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
395   static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
396   static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
397
398   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
399  
400   VARIANT v;
401   IDxDiagContainer* pDiskSubCont = NULL;
402   IDxDiagContainer* pDriversCont = NULL;
403
404   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDiskSubCont);
405   if (FAILED(hr)) { return hr; }
406   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
407   */
408   
409   /*
410    * Drivers Cont contains Files Desc Containers
411    */
412   /*
413   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, &pDriversCont);
414   if (FAILED(hr)) { return hr; }
415   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
416   */
417   return hr;
418 }
419
420 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont)
421 {
422     HRESULT hr = S_OK;
423     static const WCHAR dlls[][15] =
424     {
425         {'d','3','d','8','.','d','l','l',0},
426         {'d','3','d','9','.','d','l','l',0},
427         {'d','d','r','a','w','.','d','l','l',0},
428         {'d','e','v','e','n','u','m','.','d','l','l',0},
429         {'d','i','n','p','u','t','8','.','d','l','l',0},
430         {'d','i','n','p','u','t','.','d','l','l',0},
431         {'d','m','b','a','n','d','.','d','l','l',0},
432         {'d','m','c','o','m','p','o','s','.','d','l','l',0},
433         {'d','m','i','m','e','.','d','l','l',0},
434         {'d','m','l','o','a','d','e','r','.','d','l','l',0},
435         {'d','m','s','c','r','i','p','t','.','d','l','l',0},
436         {'d','m','s','t','y','l','e','.','d','l','l',0},
437         {'d','m','s','y','n','t','h','.','d','l','l',0},
438         {'d','m','u','s','i','c','.','d','l','l',0},
439         {'d','p','l','a','y','x','.','d','l','l',0},
440         {'d','p','n','e','t','.','d','l','l',0},
441         {'d','s','o','u','n','d','.','d','l','l',0},
442         {'d','s','w','a','v','e','.','d','l','l',0},
443         {'d','x','d','i','a','g','n','.','d','l','l',0},
444         {'q','u','a','r','t','z','.','d','l','l',0}
445     };
446     WCHAR szFilePath[MAX_PATH];
447     INT i;
448
449     GetSystemDirectoryW(szFilePath, MAX_PATH);
450
451     for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
452     {
453         static const WCHAR szFormat[] = {'%','d',0};
454         WCHAR szFileID[5];
455         IDxDiagContainer *pDXFileSubCont;
456
457         snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
458
459         hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDXFileSubCont);
460         if (FAILED(hr)) continue;
461
462         if (FAILED(DXDiag_AddFileDescContainer(pDXFileSubCont, szFilePath, dlls[i])) ||
463             FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, szFileID, pDXFileSubCont)))
464         {
465             IUnknown_Release(pDXFileSubCont);
466             continue;
467         }
468     }
469     return hr;
470 }
471
472 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
473 {
474     static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
475     static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
476     static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
477     static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
478     static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
479     static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
480     static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
481     static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
482     static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
483     static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
484     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};
485     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};
486
487     static const WCHAR szAdapterID[] = {'0',0};
488     static const WCHAR szEmpty[] = {0};
489
490     HRESULT                 hr;
491     IDxDiagContainer       *pDisplayAdapterSubCont = NULL;
492
493     IDirectDraw7           *pDirectDraw;
494     DDSCAPS2                dd_caps;
495     DISPLAY_DEVICEW         disp_dev;
496     DDSURFACEDESC2          surface_descr;
497     DWORD                   tmp;
498     WCHAR                   buffer[256];
499
500     hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
501     if (FAILED( hr )) return hr;
502     hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
503     if (FAILED( hr )) return hr;
504
505     disp_dev.cb = sizeof(disp_dev);
506     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
507     {
508         add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
509         add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
510     }
511
512     hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
513     if (FAILED( hr )) return hr;
514
515     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
516     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
517     hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
518     if (SUCCEEDED(hr))
519     {
520         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
521
522         snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
523         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
524         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
525     }
526
527     surface_descr.dwSize = sizeof(surface_descr);
528     hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
529     if (SUCCEEDED(hr))
530     {
531         if (surface_descr.dwFlags & DDSD_WIDTH)
532             add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
533         if (surface_descr.dwFlags & DDSD_HEIGHT)
534             add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
535         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
536             add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
537     }
538
539     get_display_device_id( buffer );
540     add_prop_str( pDisplayAdapterSubCont, szDeviceIdentifier, buffer );
541
542     add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
543     add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
544     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
545     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
546
547     IUnknown_Release( pDirectDraw );
548     return hr;
549 }
550
551 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
552   HRESULT hr = S_OK;
553   static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
554   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};
555   IDxDiagContainer* pSubSubCont = NULL;
556
557   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
558   if (FAILED(hr)) { return hr; }
559   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
560
561   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
562   if (FAILED(hr)) { return hr; }
563   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
564
565   return hr;
566 }
567
568 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
569   HRESULT hr = S_OK;
570   return hr;
571 }
572
573 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
574   HRESULT hr = S_OK;
575   return hr;
576 }
577
578 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
579   HRESULT hr = S_OK;
580   return hr;
581 }
582
583 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
584   HRESULT hr = S_OK;
585   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
586   static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
587   static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
588   static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
589   static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
590   static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
591   static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
592   static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
593   /*
594   static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
595   static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
596   */
597   VARIANT v;
598
599   static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
600   static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};  
601   static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
602
603   static const WCHAR szVersionFormat[] = {'v','%','d',0};
604   static const WCHAR szIdFormat[] = {'%','d',0};
605   int i = 0;
606
607
608   ICreateDevEnum* pCreateDevEnum = NULL;
609   IEnumMoniker* pEmCat = NULL;
610   IMoniker* pMCat = NULL;
611   /** */
612   hr = CoCreateInstance(&CLSID_SystemDeviceEnum, 
613                         NULL, 
614                         CLSCTX_INPROC_SERVER,
615                         &IID_ICreateDevEnum, 
616                         (void**) &pCreateDevEnum);
617   if (FAILED(hr)) return hr; 
618   
619   hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
620   if (FAILED(hr)) goto out_show_filters; 
621
622   VariantInit(&v);
623
624   while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
625     IPropertyBag* pPropBag = NULL;
626     CLSID clsidCat; 
627     hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
628     if (SUCCEEDED(hr)) {
629       WCHAR* wszCatName = NULL;
630       WCHAR* wszCatClsid = NULL;
631
632       hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
633       wszCatName = SysAllocString(V_BSTR(&v));
634       VariantClear(&v);
635
636       hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
637       wszCatClsid = SysAllocString(V_BSTR(&v));
638       hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
639       VariantClear(&v);
640
641       /*
642       hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
643       hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
644       VariantClear(&v);
645       */
646
647       if (SUCCEEDED(hr)) {
648         IEnumMoniker* pEnum = NULL;
649         IMoniker* pMoniker = NULL;
650         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);        
651         TRACE("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
652         if (FAILED(hr) || pEnum == NULL) {
653           goto class_enum_failed;
654         }
655         while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {          
656           IPropertyBag* pPropFilterBag = NULL;
657           TRACE("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
658           hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
659           if (SUCCEEDED(hr)) {
660             LPBYTE pData = NULL;
661             DWORD dwNOutputs = 0;
662             DWORD dwNInputs = 0;
663             DWORD dwMerit = 0;
664             WCHAR bufferW[10];
665             IDxDiagContainer *pDShowSubCont = NULL;
666             IFilterMapper2 *pFileMapper = NULL;
667             IAMFilterData *pFilterData = NULL;
668
669             snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
670             if (FAILED(DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDShowSubCont)) ||
671                 FAILED(IDxDiagContainerImpl_AddChildContainer(pSubCont, bufferW, pDShowSubCont)))
672             {
673               IPropertyBag_Release(pPropFilterBag);
674               if (pDShowSubCont) IUnknown_Release(pDShowSubCont);
675               continue;
676             }
677
678             bufferW[0] = 0;
679             hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
680             hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, szName, &v);
681             TRACE("\tName:%s\n", debugstr_w(V_BSTR(&v)));
682             VariantClear(&v);
683
684             hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
685             TRACE("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
686             hr = IDxDiagContainerImpl_AddProp(pDShowSubCont, ClsidFilterW, &v);
687             VariantClear(&v);
688
689             hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
690                                   (LPVOID*)&pFileMapper);
691             if (SUCCEEDED(hr) &&
692                 SUCCEEDED(IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData)))
693             {
694               DWORD array_size;
695               REGFILTER2 *pRF;
696
697               if (SUCCEEDED(IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL)) &&
698                   SUCCEEDED(SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData)))
699               {
700                 ULONG j;
701                 array_size = V_UNION(&v, parray)->rgsabound->cElements;
702
703                 if (SUCCEEDED(IAMFilterData_ParseFilterData(pFilterData, pData, array_size, (BYTE **)&pRF)))
704                 {
705                   snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
706                   if (pRF->dwVersion == 1)
707                   {
708                     for (j = 0; j < pRF->u.s.cPins; j++)
709                       if (pRF->u.s.rgPins[j].bOutput)
710                         dwNOutputs++;
711                       else
712                         dwNInputs++;
713                   }
714                   else if (pRF->dwVersion == 2)
715                   {
716                     for (j = 0; j < pRF->u.s1.cPins2; j++)
717                       if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
718                         dwNOutputs++;
719                       else
720                         dwNInputs++;
721                   }
722
723                   dwMerit = pRF->dwMerit;
724                   CoTaskMemFree(pRF);
725                 }
726
727                 SafeArrayUnaccessData(V_UNION(&v, parray));
728                 VariantClear(&v);
729               }
730               IFilterMapper2_Release(pFilterData);
731             }
732             if (pFileMapper) IFilterMapper2_Release(pFileMapper);
733
734             add_prop_str(pDShowSubCont, szVersionW, bufferW);
735             add_prop_str(pDShowSubCont, szCatName, wszCatName);
736             add_prop_str(pDShowSubCont, ClsidCatW, wszCatClsid);
737             add_prop_ui4(pDShowSubCont, dwInputs,  dwNInputs);
738             add_prop_ui4(pDShowSubCont, dwOutputs, dwNOutputs);
739             add_prop_ui4(pDShowSubCont, dwMeritW, dwMerit);
740
741             i++;
742           }
743           IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
744         }
745         IEnumMoniker_Release(pEnum); pEnum = NULL;
746       }
747 class_enum_failed:      
748       SysFreeString(wszCatName);
749       SysFreeString(wszCatClsid);
750       IPropertyBag_Release(pPropBag); pPropBag = NULL;
751     }
752     IEnumMoniker_Release(pMCat); pMCat = NULL;
753   }
754
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;
759 }
760
761 static HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
762   static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
763   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};
764   static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
765   static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
766   static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
767   static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
768   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};
769   static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
770   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};
771   static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
772
773   static const struct
774   {
775     const WCHAR *name;
776     HRESULT (*initfunc)(IDxDiagContainer*);
777   } containers[] =
778   {
779     {DxDiag_SystemInfo,        DXDiag_InitDXDiagSystemInfoContainer},
780     {DxDiag_DisplayDevices,    DXDiag_InitDXDiagDisplayContainer},
781     {DxDiag_DirectSound,       DXDiag_InitDXDiagDirectSoundContainer},
782     {DxDiag_DirectMusic,       DXDiag_InitDXDiagDirectMusicContainer},
783     {DxDiag_DirectInput,       DXDiag_InitDXDiagDirectInputContainer},
784     {DxDiag_DirectPlay,        DXDiag_InitDXDiagDirectPlayContainer},
785     {DxDiag_SystemDevices,     DXDiag_InitDXDiagSystemDevicesContainer},
786     {DxDiag_DirectXFiles,      DXDiag_InitDXDiagDirectXFilesContainer},
787     {DxDiag_DirectShowFilters, DXDiag_InitDXDiagDirectShowFiltersContainer},
788     {DxDiag_LogicalDisks,      DXDiag_InitDXDiagLogicalDisksContainer},
789   };
790
791   size_t index;
792
793   TRACE("(%p)\n", pRootCont);
794
795   for (index = 0; index < sizeof(containers)/sizeof(containers[0]); index++)
796   {
797     IDxDiagContainer* pSubCont;
798     HRESULT hr;
799
800     hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
801     if (FAILED(hr))
802       return hr;
803
804     hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, containers[index].name, pSubCont);
805     if (FAILED(hr))
806     {
807       IDxDiagContainer_Release(pSubCont);
808       return hr;
809     }
810
811     /* The return value is ignored for now. */
812     containers[index].initfunc(pSubCont);
813   }
814
815   return S_OK;
816 }