winenas.drv: Avoid a warning in a trace on x86_64.
[wine] / dlls / dxdiagn / provider.c
1 /* 
2  * IDxDiagProvider Implementation
3  * 
4  * Copyright 2004-2005 Raphael Junqueira
5  * Copyright 2010 Andrew Nguyen
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  */
22
23 #include "config.h"
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "dxdiag_private.h"
29 #include "wine/unicode.h"
30 #include "winver.h"
31 #include "objidl.h"
32 #include "dshow.h"
33 #include "vfw.h"
34 #include "mmddk.h"
35 #include "ddraw.h"
36 #include "d3d9.h"
37 #include "strmif.h"
38 #include "initguid.h"
39 #include "fil_data.h"
40 #include "psapi.h"
41
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
45
46 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
47 static void free_information_tree(IDxDiagContainerImpl_Container *node);
48
49 /* IDxDiagProvider IUnknown parts follow: */
50 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
51 {
52     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
53
54     if (!ppobj) return E_INVALIDARG;
55
56     if (IsEqualGUID(riid, &IID_IUnknown)
57         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
58         IUnknown_AddRef(iface);
59         *ppobj = This;
60         return S_OK;
61     }
62
63     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
64     *ppobj = NULL;
65     return E_NOINTERFACE;
66 }
67
68 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
69     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
70     ULONG refCount = InterlockedIncrement(&This->ref);
71
72     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
73
74     DXDIAGN_LockModule();
75
76     return refCount;
77 }
78
79 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
80     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
81     ULONG refCount = InterlockedDecrement(&This->ref);
82
83     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
84
85     if (!refCount) {
86         free_information_tree(This->info_root);
87         HeapFree(GetProcessHeap(), 0, This);
88     }
89
90     DXDIAGN_UnlockModule();
91     
92     return refCount;
93 }
94
95 /* IDxDiagProvider Interface follow: */
96 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
97     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
98     HRESULT hr;
99
100     TRACE("(%p,%p)\n", iface, pParams);
101
102     if (NULL == pParams) {
103       return E_POINTER;
104     }
105     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
106         pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
107       return E_INVALIDARG;
108     }
109
110     if (!This->info_root)
111     {
112         hr = build_information_tree(&This->info_root);
113         if (FAILED(hr))
114             return hr;
115     }
116
117     This->init = TRUE;
118     memcpy(&This->params, pParams, pParams->dwSize);
119     return S_OK;
120 }
121
122 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
123   IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
124
125   TRACE("(%p,%p)\n", iface, ppInstance);
126
127   if (FALSE == This->init) {
128     return CO_E_NOTINITIALIZED;
129   }
130
131   return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
132                                       (IDxDiagProvider *)This, (void **)ppInstance);
133 }
134
135 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
136 {
137     IDxDiagProviderImpl_QueryInterface,
138     IDxDiagProviderImpl_AddRef,
139     IDxDiagProviderImpl_Release,
140     IDxDiagProviderImpl_Initialize,
141     IDxDiagProviderImpl_GetRootContainer
142 };
143
144 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
145   IDxDiagProviderImpl* provider;
146
147   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
148
149   *ppobj = NULL;
150   if (punkOuter) return CLASS_E_NOAGGREGATION;
151
152   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
153   if (NULL == provider) return E_OUTOFMEMORY;
154   provider->lpVtbl = &DxDiagProvider_Vtbl;
155   provider->ref = 0; /* will be inited with QueryInterface */
156   return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
157 }
158
159 static void get_display_device_id(WCHAR *szIdentifierBuffer)
160 {
161     static const WCHAR szNA[] = {'n','/','a',0};
162
163     HRESULT hr = E_FAIL;
164
165     HMODULE                 d3d9_handle;
166     IDirect3D9             *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
167     IDirect3D9             *pD3d = NULL;
168     D3DADAPTER_IDENTIFIER9  adapter_ident;
169
170     /* Retrieves the display device identifier from the d3d9 implementation. */
171     d3d9_handle = LoadLibraryA("d3d9.dll");
172     if(d3d9_handle)
173         pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
174     if(pDirect3DCreate9)
175         pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
176     if(pD3d)
177         hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
178     if(SUCCEEDED(hr)) {
179         StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
180     } else {
181         memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
182     }
183
184     if (pD3d)
185         IDirect3D9_Release(pD3d);
186     if (d3d9_handle)
187         FreeLibrary(d3d9_handle);
188 }
189
190 static void free_property_information(IDxDiagContainerImpl_Property *prop)
191 {
192     VariantClear(&prop->vProp);
193     HeapFree(GetProcessHeap(), 0, prop->propName);
194     HeapFree(GetProcessHeap(), 0, prop);
195 }
196
197 static void free_information_tree(IDxDiagContainerImpl_Container *node)
198 {
199     IDxDiagContainerImpl_Container *ptr, *cursor2;
200
201     if (!node)
202         return;
203
204     HeapFree(GetProcessHeap(), 0, node->contName);
205
206     LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
207     {
208         IDxDiagContainerImpl_Property *prop, *prop_cursor2;
209
210         LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
211         {
212             list_remove(&prop->entry);
213             free_property_information(prop);
214         }
215
216         list_remove(&ptr->entry);
217         free_information_tree(ptr);
218     }
219
220     HeapFree(GetProcessHeap(), 0, node);
221 }
222
223 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
224 {
225     IDxDiagContainerImpl_Container *ret;
226
227     ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
228     if (!ret)
229         return NULL;
230
231     if (name)
232     {
233         ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
234         if (!ret->contName)
235         {
236             HeapFree(GetProcessHeap(), 0, ret);
237             return NULL;
238         }
239         strcpyW(ret->contName, name);
240     }
241
242     list_init(&ret->subContainers);
243     list_init(&ret->properties);
244
245     return ret;
246 }
247
248 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
249 {
250     IDxDiagContainerImpl_Property *ret;
251
252     ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
253     if (!ret)
254         return NULL;
255
256     ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
257     if (!ret->propName)
258     {
259         HeapFree(GetProcessHeap(), 0, ret);
260         return NULL;
261     }
262     strcpyW(ret->propName, name);
263
264     return ret;
265 }
266
267 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
268 {
269     list_add_tail(&node->subContainers, &subCont->entry);
270     ++node->nSubContainers;
271 }
272
273 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
274 {
275     IDxDiagContainerImpl_Property *prop;
276     BSTR bstr;
277
278     prop = allocate_property_information(propName);
279     if (!prop)
280         return E_OUTOFMEMORY;
281
282     bstr = SysAllocString(str);
283     if (!bstr)
284     {
285         free_property_information(prop);
286         return E_OUTOFMEMORY;
287     }
288
289     V_VT(&prop->vProp) = VT_BSTR;
290     V_BSTR(&prop->vProp) = bstr;
291
292     list_add_tail(&node->properties, &prop->entry);
293     ++node->nProperties;
294
295     return S_OK;
296 }
297
298 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
299 {
300     IDxDiagContainerImpl_Property *prop;
301
302     prop = allocate_property_information(propName);
303     if (!prop)
304         return E_OUTOFMEMORY;
305
306     V_VT(&prop->vProp) = VT_UI4;
307     V_UI4(&prop->vProp) = data;
308
309     list_add_tail(&node->properties, &prop->entry);
310     ++node->nProperties;
311
312     return S_OK;
313 }
314
315 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
316 {
317     IDxDiagContainerImpl_Property *prop;
318
319     prop = allocate_property_information(propName);
320     if (!prop)
321         return E_OUTOFMEMORY;
322
323     V_VT(&prop->vProp) = VT_BOOL;
324     V_BOOL(&prop->vProp) = data;
325
326     list_add_tail(&node->properties, &prop->entry);
327     ++node->nProperties;
328
329     return S_OK;
330 }
331
332 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
333 {
334     IDxDiagContainerImpl_Property *prop;
335
336     prop = allocate_property_information(propName);
337     if (!prop)
338         return E_OUTOFMEMORY;
339
340     V_VT(&prop->vProp) = VT_UI8;
341     V_UI8(&prop->vProp) = data;
342
343     VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
344
345     list_add_tail(&node->properties, &prop->entry);
346     ++node->nProperties;
347
348     return S_OK;
349 }
350
351 /* Copied from programs/taskkill/taskkill.c. */
352 static DWORD *enumerate_processes(DWORD *list_count)
353 {
354     DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
355
356     pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
357     if (!pid_list)
358         return NULL;
359
360     for (;;)
361     {
362         DWORD *realloc_list;
363
364         if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
365         {
366             HeapFree(GetProcessHeap(), 0, pid_list);
367             return NULL;
368         }
369
370         /* EnumProcesses can't signal an insufficient buffer condition, so the
371          * only way to possibly determine whether a larger buffer is required
372          * is to see whether the written number of bytes is the same as the
373          * buffer size. If so, the buffer will be reallocated to twice the
374          * size. */
375         if (alloc_bytes != needed_bytes)
376             break;
377
378         alloc_bytes *= 2;
379         realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
380         if (!realloc_list)
381         {
382             HeapFree(GetProcessHeap(), 0, pid_list);
383             return NULL;
384         }
385         pid_list = realloc_list;
386     }
387
388     *list_count = needed_bytes / sizeof(*pid_list);
389     return pid_list;
390 }
391
392 /* Copied from programs/taskkill/taskkill.c. */
393 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
394 {
395     HANDLE process;
396     HMODULE module;
397     DWORD required_size;
398
399     process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
400     if (!process)
401         return FALSE;
402
403     if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
404     {
405         CloseHandle(process);
406         return FALSE;
407     }
408
409     if (!GetModuleBaseNameW(process, module, buf, chars))
410     {
411         CloseHandle(process);
412         return FALSE;
413     }
414
415     CloseHandle(process);
416     return TRUE;
417 }
418
419 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
420 static BOOL is_netmeeting_running(void)
421 {
422     static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
423
424     DWORD list_count;
425     DWORD *pid_list = enumerate_processes(&list_count);
426
427     if (pid_list)
428     {
429         DWORD i;
430         WCHAR process_name[MAX_PATH];
431
432         for (i = 0; i < list_count; i++)
433         {
434             if (get_process_name_from_pid(pid_list[i], process_name, sizeof(process_name)/sizeof(WCHAR)) &&
435                 !lstrcmpW(conf_exe, process_name))
436             {
437                 HeapFree(GetProcessHeap(), 0, pid_list);
438                 return TRUE;
439             }
440         }
441         HeapFree(GetProcessHeap(), 0, pid_list);
442     }
443
444     return FALSE;
445 }
446
447 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
448 {
449     static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
450     static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
451     static const WCHAR szLanguagesLocalized[] = {'s','z','L','a','n','g','u','a','g','e','s','L','o','c','a','l','i','z','e','d',0};
452     static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
453
454     WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
455     HRESULT hr;
456
457     /* szLanguagesLocalized */
458     GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
459     LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
460     GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
461
462     snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
463
464     hr = add_bstr_property(node, szLanguagesLocalized, language_str);
465     if (FAILED(hr))
466         return hr;
467
468     /* szLanguagesEnglish */
469     GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
470     GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
471
472     snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
473
474     hr = add_bstr_property(node, szLanguagesEnglish, language_str);
475     if (FAILED(hr))
476         return hr;
477
478     return S_OK;
479 }
480
481 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
482 {
483     static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
484     static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
485     static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
486     static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
487     static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
488
489     SYSTEMTIME curtime;
490     WCHAR date_str[80], time_str[80], datetime_str[200];
491     HRESULT hr;
492
493     GetLocalTime(&curtime);
494
495     GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, sizeof(time_str)/sizeof(WCHAR));
496
497     /* szTimeLocalized */
498     GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, sizeof(date_str)/sizeof(WCHAR));
499
500     snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
501
502     hr = add_bstr_property(node, szTimeLocalized, datetime_str);
503     if (FAILED(hr))
504         return hr;
505
506     /* szTimeEnglish */
507     GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, sizeof(date_str)/sizeof(WCHAR));
508
509     snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
510
511     hr = add_bstr_property(node, szTimeEnglish, datetime_str);
512     if (FAILED(hr))
513         return hr;
514
515     return S_OK;
516 }
517
518 static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
519 {
520     static const WCHAR winxpW[] = {'W','i','n','d','o','w','s',' ','X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
521     static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
522     static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
523     static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
524     static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
525     static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
526     static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
527
528     static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
529                                        szOSEnglish, szOSExEnglish, szOSExLongEnglish};
530
531     size_t i;
532     HRESULT hr;
533
534     /* FIXME: OS detection should be performed, and localized OS strings
535      * should contain translated versions of the "build" phrase. */
536     for (i = 0; i < sizeof(prop_list)/sizeof(prop_list[0]); i++)
537     {
538         hr = add_bstr_property(node, prop_list[i], winxpW);
539         if (FAILED(hr))
540             return hr;
541     }
542
543     return S_OK;
544 }
545
546 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
547 {
548     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};
549     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};
550     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};
551     static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
552     static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
553     static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
554     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};
555     static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
556     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};
557     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};
558     static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
559     static const WCHAR ullUsedPageFile[]   = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
560     static const WCHAR ullAvailPageFile[]  = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
561     static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
562     static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
563     static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
564     static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
565     static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
566     static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
567     static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
568     static const WCHAR szPhysicalMemoryEnglish[] = {'s','z','P','h','y','s','i','c','a','l','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
569     static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
570     static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
571     static const WCHAR szMachineNameLocalized[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','L','o','c','a','l','i','z','e','d',0};
572     static const WCHAR szMachineNameEnglish[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','E','n','g','l','i','s','h',0};
573
574     static const WCHAR pagefile_fmtW[] = {'%','u','M','B',' ','u','s','e','d',',',' ','%','u','M','B',' ','a','v','a','i','l','a','b','l','e',0};
575     static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
576
577     HRESULT hr;
578     MEMORYSTATUSEX msex;
579     OSVERSIONINFOW info;
580     DWORD count, usedpage_mb, availpage_mb;
581     WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
582
583     hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
584     if (FAILED(hr))
585         return hr;
586
587     hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
588     if (FAILED(hr))
589         return hr;
590
591     hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
592     if (FAILED(hr))
593         return hr;
594
595     hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
596     if (FAILED(hr))
597         return hr;
598
599     hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
600     if (FAILED(hr))
601         return hr;
602
603     hr = add_bool_property(node, bDebug, FALSE);
604     if (FAILED(hr))
605         return hr;
606
607     hr = add_bool_property(node, bNECPC98, FALSE);
608     if (FAILED(hr))
609         return hr;
610
611     msex.dwLength = sizeof(msex);
612     GlobalMemoryStatusEx(&msex);
613
614     hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
615     if (FAILED(hr))
616         return hr;
617
618     hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
619     if (FAILED(hr))
620         return hr;
621
622     hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
623     if (FAILED(hr))
624         return hr;
625
626     hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
627     if (FAILED(hr))
628         return hr;
629
630     info.dwOSVersionInfoSize = sizeof(info);
631     GetVersionExW(&info);
632
633     hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
634     if (FAILED(hr))
635         return hr;
636
637     hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
638     if (FAILED(hr))
639         return hr;
640
641     hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
642     if (FAILED(hr))
643         return hr;
644
645     hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
646     if (FAILED(hr))
647         return hr;
648
649     hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
650     if (FAILED(hr))
651         return hr;
652
653     /* FIXME: Roundoff should not be done with truncated division. */
654     snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
655     hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
656     if (FAILED(hr))
657         return hr;
658
659     usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
660     availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
661     LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
662     snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), localized_pagefile_fmt, usedpage_mb, availpage_mb);
663
664     hr = add_bstr_property(node, szPageFileLocalized, print_buf);
665     if (FAILED(hr))
666         return hr;
667
668     snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
669
670     hr = add_bstr_property(node, szPageFileEnglish, print_buf);
671     if (FAILED(hr))
672         return hr;
673
674     GetWindowsDirectoryW(buffer, MAX_PATH);
675
676     hr = add_bstr_property(node, szWindowsDir, buffer);
677     if (FAILED(hr))
678         return hr;
679
680     count = sizeof(computer_name)/sizeof(WCHAR);
681     if (!GetComputerNameW(computer_name, &count))
682         return E_FAIL;
683
684     hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
685     if (FAILED(hr))
686         return hr;
687
688     hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
689     if (FAILED(hr))
690         return hr;
691
692     hr = fill_language_information(node);
693     if (FAILED(hr))
694         return hr;
695
696     hr = fill_datetime_information(node);
697     if (FAILED(hr))
698         return hr;
699
700     hr = fill_os_string_information(node, &info);
701     if (FAILED(hr))
702         return hr;
703
704     return S_OK;
705 }
706
707 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
708 {
709     static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
710     static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
711     static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
712     static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
713     static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
714     static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
715     static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
716     static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
717     static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
718     static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
719     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};
720     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};
721
722     static const WCHAR szAdapterID[] = {'0',0};
723     static const WCHAR szEmpty[] = {0};
724
725     IDxDiagContainerImpl_Container *display_adapter;
726     HRESULT hr;
727     IDirectDraw7 *pDirectDraw;
728     DDSCAPS2 dd_caps;
729     DISPLAY_DEVICEW disp_dev;
730     DDSURFACEDESC2 surface_descr;
731     DWORD tmp;
732     WCHAR buffer[256];
733
734     display_adapter = allocate_information_node(szAdapterID);
735     if (!display_adapter)
736         return E_OUTOFMEMORY;
737
738     add_subcontainer(node, display_adapter);
739
740     disp_dev.cb = sizeof(disp_dev);
741     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
742     {
743         hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
744         if (FAILED(hr))
745             return hr;
746
747         hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
748         if (FAILED(hr))
749             return hr;
750     }
751
752     /* For now, silently ignore a failure from DirectDrawCreateEx. */
753     hr = DirectDrawCreateEx(NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
754     if (FAILED(hr))
755         return S_OK;
756
757     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
758     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
759     hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
760     if (SUCCEEDED(hr))
761     {
762         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
763
764         snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0);
765
766         hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
767         if (FAILED(hr))
768             goto cleanup;
769
770         hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
771         if (FAILED(hr))
772             goto cleanup;
773     }
774
775     surface_descr.dwSize = sizeof(surface_descr);
776     hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
777     if (SUCCEEDED(hr))
778     {
779         if (surface_descr.dwFlags & DDSD_WIDTH)
780         {
781             hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
782             if (FAILED(hr))
783                 goto cleanup;
784         }
785
786         if (surface_descr.dwFlags & DDSD_HEIGHT)
787         {
788             hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
789             if (FAILED(hr))
790                 goto cleanup;
791         }
792
793         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
794         {
795             hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
796             if (FAILED(hr))
797                 goto cleanup;
798         }
799     }
800
801     get_display_device_id(buffer);
802
803     hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
804     if (FAILED(hr))
805         goto cleanup;
806
807     hr = add_bstr_property(display_adapter, szVendorId, szEmpty);
808     if (FAILED(hr))
809         goto cleanup;
810
811     hr = add_bstr_property(display_adapter, szDeviceId, szEmpty);
812     if (FAILED(hr))
813         goto cleanup;
814
815     hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
816     if (FAILED(hr))
817         goto cleanup;
818
819     hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
820     if (FAILED(hr))
821         goto cleanup;
822
823     hr = S_OK;
824 cleanup:
825     IDirectDraw7_Release(pDirectDraw);
826     return hr;
827 }
828
829 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
830 {
831     static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
832     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};
833
834     IDxDiagContainerImpl_Container *cont;
835
836     cont = allocate_information_node(DxDiag_SoundDevices);
837     if (!cont)
838         return E_OUTOFMEMORY;
839
840     add_subcontainer(node, cont);
841
842     cont = allocate_information_node(DxDiag_SoundCaptureDevices);
843     if (!cont)
844         return E_OUTOFMEMORY;
845
846     add_subcontainer(node, cont);
847
848     return S_OK;
849 }
850
851 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
852 {
853     return S_OK;
854 }
855
856 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
857 {
858     return S_OK;
859 }
860
861 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
862 {
863     return S_OK;
864 }
865
866 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
867 {
868     return S_OK;
869 }
870
871 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
872 {
873     static const WCHAR szSlashSep[] = {'\\',0};
874     static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
875     static const WCHAR szName[] = {'s','z','N','a','m','e',0};
876     static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
877     static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
878     static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
879     static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
880     static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
881     static const WCHAR bBeta[] = {'b','B','e','t','a',0};
882     static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
883     static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
884
885     /* Values */
886     static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
887     static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
888     static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
889
890     HRESULT hr;
891     WCHAR *szFile;
892     WCHAR szVersion_v[1024];
893     DWORD retval, hdl;
894     void *pVersionInfo = NULL;
895     BOOL boolret = FALSE;
896     UINT uiLength;
897     VS_FIXEDFILEINFO *pFileInfo;
898
899     TRACE("Filling container %p for %s in %s\n", node,
900           debugstr_w(szFileName), debugstr_w(szFilePath));
901
902     szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
903                                             lstrlenW(szFileName) + 2 /* slash + terminator */));
904     if (!szFile)
905         return E_OUTOFMEMORY;
906
907     lstrcpyW(szFile, szFilePath);
908     lstrcatW(szFile, szSlashSep);
909     lstrcatW(szFile, szFileName);
910
911     retval = GetFileVersionInfoSizeW(szFile, &hdl);
912     if (retval)
913     {
914         pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
915         if (!pVersionInfo)
916         {
917             hr = E_OUTOFMEMORY;
918             goto cleanup;
919         }
920
921         if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
922             VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
923             boolret = TRUE;
924     }
925
926     hr = add_bstr_property(node, szPath, szFile);
927     if (FAILED(hr))
928         goto cleanup;
929
930     hr = add_bstr_property(node, szName, szFileName);
931     if (FAILED(hr))
932         goto cleanup;
933
934     hr = add_bool_property(node, bExists, boolret);
935     if (FAILED(hr))
936         goto cleanup;
937
938     if (boolret)
939     {
940         snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
941                   szVersionFormat,
942                   HIWORD(pFileInfo->dwFileVersionMS),
943                   LOWORD(pFileInfo->dwFileVersionMS),
944                   HIWORD(pFileInfo->dwFileVersionLS),
945                   LOWORD(pFileInfo->dwFileVersionLS));
946
947         TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
948
949         hr = add_bstr_property(node, szVersion, szVersion_v);
950         if (FAILED(hr))
951             goto cleanup;
952
953         hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
954         if (FAILED(hr))
955             goto cleanup;
956
957         hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
958         if (FAILED(hr))
959             goto cleanup;
960
961         hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
962         if (FAILED(hr))
963             goto cleanup;
964
965         hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
966         if (FAILED(hr))
967             goto cleanup;
968
969         hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
970         if (FAILED(hr))
971             goto cleanup;
972
973         hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
974         if (FAILED(hr))
975             goto cleanup;
976     }
977
978     hr = S_OK;
979 cleanup:
980     HeapFree(GetProcessHeap(), 0, pVersionInfo);
981     HeapFree(GetProcessHeap(), 0, szFile);
982
983     return hr;
984 }
985 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
986 {
987     static const WCHAR dlls[][15] =
988     {
989         {'d','3','d','8','.','d','l','l',0},
990         {'d','3','d','9','.','d','l','l',0},
991         {'d','d','r','a','w','.','d','l','l',0},
992         {'d','e','v','e','n','u','m','.','d','l','l',0},
993         {'d','i','n','p','u','t','8','.','d','l','l',0},
994         {'d','i','n','p','u','t','.','d','l','l',0},
995         {'d','m','b','a','n','d','.','d','l','l',0},
996         {'d','m','c','o','m','p','o','s','.','d','l','l',0},
997         {'d','m','i','m','e','.','d','l','l',0},
998         {'d','m','l','o','a','d','e','r','.','d','l','l',0},
999         {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1000         {'d','m','s','t','y','l','e','.','d','l','l',0},
1001         {'d','m','s','y','n','t','h','.','d','l','l',0},
1002         {'d','m','u','s','i','c','.','d','l','l',0},
1003         {'d','p','l','a','y','x','.','d','l','l',0},
1004         {'d','p','n','e','t','.','d','l','l',0},
1005         {'d','s','o','u','n','d','.','d','l','l',0},
1006         {'d','s','w','a','v','e','.','d','l','l',0},
1007         {'d','x','d','i','a','g','n','.','d','l','l',0},
1008         {'q','u','a','r','t','z','.','d','l','l',0}
1009     };
1010
1011     HRESULT hr;
1012     WCHAR szFilePath[MAX_PATH];
1013     INT i;
1014
1015     GetSystemDirectoryW(szFilePath, MAX_PATH);
1016
1017     for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
1018     {
1019         static const WCHAR szFormat[] = {'%','d',0};
1020
1021         WCHAR szFileID[5];
1022         IDxDiagContainerImpl_Container *file_container;
1023
1024         snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
1025
1026         file_container = allocate_information_node(szFileID);
1027         if (!file_container)
1028             return E_OUTOFMEMORY;
1029
1030         hr = fill_file_description(file_container, szFilePath, dlls[i]);
1031         if (FAILED(hr))
1032         {
1033             free_information_tree(file_container);
1034             continue;
1035         }
1036
1037         add_subcontainer(node, file_container);
1038     }
1039
1040     return S_OK;
1041 }
1042
1043 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1044 {
1045     static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1046     static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1047
1048     HRESULT hr;
1049
1050     VariantInit(friendly_name);
1051     VariantInit(clsid_name);
1052
1053     hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1054     if (FAILED(hr))
1055         return hr;
1056
1057     hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1058     if (FAILED(hr))
1059     {
1060         VariantClear(friendly_name);
1061         return hr;
1062     }
1063
1064     return S_OK;
1065 }
1066
1067 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1068 {
1069     static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1070     static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1071     static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1072     static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1073     static const WCHAR szVersionFormat[] = {'v','%','d',0};
1074
1075     HRESULT hr;
1076     IFilterMapper2 *pFileMapper = NULL;
1077     IAMFilterData *pFilterData = NULL;
1078     REGFILTER2 *pRF = NULL;
1079     WCHAR bufferW[10];
1080     ULONG j;
1081     DWORD dwNOutputs = 0;
1082     DWORD dwNInputs = 0;
1083
1084     hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1085                           (void **)&pFileMapper);
1086     if (FAILED(hr))
1087         return hr;
1088
1089     hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1090     if (FAILED(hr))
1091         goto cleanup;
1092
1093     hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&pRF);
1094     if (FAILED(hr))
1095         goto cleanup;
1096
1097     snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1098     hr = add_bstr_property(subcont, szVersionW, bufferW);
1099     if (FAILED(hr))
1100         goto cleanup;
1101
1102     if (pRF->dwVersion == 1)
1103     {
1104         for (j = 0; j < pRF->u.s.cPins; j++)
1105             if (pRF->u.s.rgPins[j].bOutput)
1106                 dwNOutputs++;
1107             else
1108                 dwNInputs++;
1109     }
1110     else if (pRF->dwVersion == 2)
1111     {
1112         for (j = 0; j < pRF->u.s1.cPins2; j++)
1113             if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1114                 dwNOutputs++;
1115             else
1116                 dwNInputs++;
1117     }
1118
1119     hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1120     if (FAILED(hr))
1121         goto cleanup;
1122
1123     hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1124     if (FAILED(hr))
1125         goto cleanup;
1126
1127     hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1128     if (FAILED(hr))
1129         goto cleanup;
1130
1131     hr = S_OK;
1132 cleanup:
1133     CoTaskMemFree(pRF);
1134     if (pFilterData) IAMFilterData_Release(pFilterData);
1135     if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1136
1137     return hr;
1138 }
1139
1140 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1141 {
1142     static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1143     static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1144     static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1145
1146     HRESULT hr;
1147     IPropertyBag *pPropFilterBag = NULL;
1148     BYTE *pData;
1149     VARIANT friendly_name;
1150     VARIANT clsid_name;
1151     VARIANT v;
1152
1153     VariantInit(&friendly_name);
1154     VariantInit(&clsid_name);
1155     VariantInit(&v);
1156
1157     hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1158     if (FAILED(hr))
1159         return hr;
1160
1161     hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1162     if (FAILED(hr))
1163         goto cleanup;
1164
1165     TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1166     TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1167
1168     hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1169     if (FAILED(hr))
1170         goto cleanup;
1171
1172     hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1173     if (FAILED(hr))
1174         goto cleanup;
1175
1176     hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1177     if (FAILED(hr))
1178         goto cleanup;
1179
1180     hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1181     if (FAILED(hr))
1182         goto cleanup;
1183
1184     hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1185     SafeArrayUnaccessData(V_ARRAY(&v));
1186     if (FAILED(hr))
1187         goto cleanup;
1188
1189     hr = S_OK;
1190 cleanup:
1191     VariantClear(&v);
1192     VariantClear(&clsid_name);
1193     VariantClear(&friendly_name);
1194     if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1195
1196     return hr;
1197 }
1198
1199 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1200 {
1201     static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1202     static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1203     static const WCHAR szIdFormat[] = {'%','d',0};
1204
1205     HRESULT hr;
1206     int i = 0;
1207     ICreateDevEnum *pCreateDevEnum;
1208     IEnumMoniker *pEmCat = NULL;
1209     IMoniker *pMCat = NULL;
1210         IEnumMoniker *pEnum = NULL;
1211
1212     hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1213                           &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1214     if (FAILED(hr))
1215         return hr;
1216
1217     hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1218     if (FAILED(hr))
1219         goto cleanup;
1220
1221     while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1222     {
1223         VARIANT vCatName;
1224         VARIANT vCatClsid;
1225         IPropertyBag *pPropBag;
1226         CLSID clsidCat;
1227         IMoniker *pMoniker = NULL;
1228
1229         hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1230         if (FAILED(hr))
1231         {
1232             IMoniker_Release(pMCat);
1233             break;
1234         }
1235
1236         hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1237         IPropertyBag_Release(pPropBag);
1238         if (FAILED(hr))
1239         {
1240             IMoniker_Release(pMCat);
1241             break;
1242         }
1243
1244         hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1245         if (FAILED(hr))
1246         {
1247             IMoniker_Release(pMCat);
1248             VariantClear(&vCatClsid);
1249             VariantClear(&vCatName);
1250             break;
1251         }
1252
1253         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1254         if (hr != S_OK)
1255         {
1256             IMoniker_Release(pMCat);
1257             VariantClear(&vCatClsid);
1258             VariantClear(&vCatName);
1259             continue;
1260         }
1261
1262         TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1263
1264         while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1265         {
1266             WCHAR bufferW[10];
1267             IDxDiagContainerImpl_Container *subcont;
1268
1269             snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1270             subcont = allocate_information_node(bufferW);
1271             if (!subcont)
1272             {
1273                 hr = E_OUTOFMEMORY;
1274                 IMoniker_Release(pMoniker);
1275                 break;
1276             }
1277
1278             hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1279             if (FAILED(hr))
1280             {
1281                 free_information_tree(subcont);
1282                 IMoniker_Release(pMoniker);
1283                 break;
1284             }
1285
1286             hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1287             if (FAILED(hr))
1288             {
1289                 free_information_tree(subcont);
1290                 IMoniker_Release(pMoniker);
1291                 break;
1292             }
1293
1294             hr = fill_filter_container(subcont, pMoniker);
1295             if (FAILED(hr))
1296             {
1297                 free_information_tree(subcont);
1298                 IMoniker_Release(pMoniker);
1299                 break;
1300             }
1301
1302             add_subcontainer(node, subcont);
1303             i++;
1304             IMoniker_Release(pMoniker);
1305         }
1306
1307         IEnumMoniker_Release(pEnum);
1308         IMoniker_Release(pMCat);
1309         VariantClear(&vCatClsid);
1310         VariantClear(&vCatName);
1311
1312         if (FAILED(hr))
1313             break;
1314     }
1315
1316 cleanup:
1317     if (pEmCat) IEnumMoniker_Release(pEmCat);
1318     ICreateDevEnum_Release(pCreateDevEnum);
1319     return hr;
1320 }
1321
1322 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1323 {
1324     return S_OK;
1325 }
1326
1327 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1328 {
1329     static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1330     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};
1331     static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1332     static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1333     static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1334     static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1335     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};
1336     static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1337     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};
1338     static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1339
1340     static const struct
1341     {
1342         const WCHAR *name;
1343         HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1344     } root_children[] =
1345     {
1346         {DxDiag_SystemInfo, build_systeminfo_tree},
1347         {DxDiag_DisplayDevices, build_displaydevices_tree},
1348         {DxDiag_DirectSound, build_directsound_tree},
1349         {DxDiag_DirectMusic, build_directmusic_tree},
1350         {DxDiag_DirectInput, build_directinput_tree},
1351         {DxDiag_DirectPlay, build_directplay_tree},
1352         {DxDiag_SystemDevices, build_systemdevices_tree},
1353         {DxDiag_DirectXFiles, build_directxfiles_tree},
1354         {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1355         {DxDiag_LogicalDisks, build_logicaldisks_tree},
1356     };
1357
1358     IDxDiagContainerImpl_Container *info_root;
1359     size_t index;
1360
1361     info_root = allocate_information_node(NULL);
1362     if (!info_root)
1363         return E_OUTOFMEMORY;
1364
1365     for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1366     {
1367         IDxDiagContainerImpl_Container *node;
1368         HRESULT hr;
1369
1370         node = allocate_information_node(root_children[index].name);
1371         if (!node)
1372         {
1373             free_information_tree(info_root);
1374             return E_OUTOFMEMORY;
1375         }
1376
1377         hr = root_children[index].initfunc(node);
1378         if (FAILED(hr))
1379         {
1380             free_information_tree(node);
1381             free_information_tree(info_root);
1382             return hr;
1383         }
1384
1385         add_subcontainer(info_root, node);
1386     }
1387
1388     *pinfo_root = info_root;
1389     return S_OK;
1390 }