[DXDIAGN]
[reactos.git] / reactos / dll / directx / wine / 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 "dxdiag_private.h"
24
25 #include <winver.h>
26 #include <uuids.h>
27 #include <d3d9.h>
28 #include <fil_data.h>
29 #include <psapi.h>
30 #include <wbemcli.h>
31
32 static const WCHAR szEmpty[] = {0};
33
34 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
35 static void free_information_tree(IDxDiagContainerImpl_Container *node);
36
37 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
38 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
39 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
40 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
41 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
42 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
43 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
44 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
45 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
46 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
47 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};
48 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};
49 static const WCHAR szDriverName[] = {'s','z','D','r','i','v','e','r','N','a','m','e',0};
50 static const WCHAR szDriverVersion[] = {'s','z','D','r','i','v','e','r','V','e','r','s','i','o','n',0};
51 static const WCHAR szSubSysId[] = {'s','z','S','u','b','S','y','s','I','d',0};
52 static const WCHAR szRevisionId[] = {'s','z','R','e','v','i','s','i','o','n','I','d',0};
53 static const WCHAR dwRefreshRate[] = {'d','w','R','e','f','r','e','s','h','R','a','t','e',0};
54 static const WCHAR szManufacturer[] = {'s','z','M','a','n','u','f','a','c','t','u','r','e','r',0};
55 static const WCHAR szChipType[] = {'s','z','C','h','i','p','T','y','p','e',0};
56 static const WCHAR szDACType[] = {'s','z','D','A','C','T','y','p','e',0};
57 static const WCHAR szRevision[] = {'s','z','R','e','v','i','s','i','o','n',0};
58
59 struct IDxDiagProviderImpl
60 {
61 IDxDiagProvider IDxDiagProvider_iface;
62 LONG ref;
63 BOOL init;
64 DXDIAG_INIT_PARAMS params;
65 IDxDiagContainerImpl_Container *info_root;
66 };
67
68 static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
69 {
70 return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
71 }
72
73 /* IDxDiagProvider IUnknown parts follow: */
74 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
75 void **ppobj)
76 {
77 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
78
79 if (!ppobj) return E_INVALIDARG;
80
81 if (IsEqualGUID(riid, &IID_IUnknown)
82 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
83 IUnknown_AddRef(iface);
84 *ppobj = This;
85 return S_OK;
86 }
87
88 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
89 *ppobj = NULL;
90 return E_NOINTERFACE;
91 }
92
93 static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
94 {
95 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
96 ULONG refCount = InterlockedIncrement(&This->ref);
97
98 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
99
100 DXDIAGN_LockModule();
101
102 return refCount;
103 }
104
105 static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
106 {
107 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
108 ULONG refCount = InterlockedDecrement(&This->ref);
109
110 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
111
112 if (!refCount) {
113 free_information_tree(This->info_root);
114 HeapFree(GetProcessHeap(), 0, This);
115 }
116
117 DXDIAGN_UnlockModule();
118
119 return refCount;
120 }
121
122 /* IDxDiagProvider Interface follow: */
123 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
124 DXDIAG_INIT_PARAMS *pParams)
125 {
126 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
127 HRESULT hr;
128
129 TRACE("(%p,%p)\n", iface, pParams);
130
131 if (NULL == pParams) {
132 return E_POINTER;
133 }
134 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
135 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
136 return E_INVALIDARG;
137 }
138
139 if (!This->info_root)
140 {
141 hr = build_information_tree(&This->info_root);
142 if (FAILED(hr))
143 return hr;
144 }
145
146 This->init = TRUE;
147 memcpy(&This->params, pParams, pParams->dwSize);
148 return S_OK;
149 }
150
151 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
152 IDxDiagContainer **ppInstance)
153 {
154 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
155
156 TRACE("(%p,%p)\n", iface, ppInstance);
157
158 if (FALSE == This->init) {
159 return CO_E_NOTINITIALIZED;
160 }
161
162 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
163 &This->IDxDiagProvider_iface, (void **)ppInstance);
164 }
165
166 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
167 {
168 IDxDiagProviderImpl_QueryInterface,
169 IDxDiagProviderImpl_AddRef,
170 IDxDiagProviderImpl_Release,
171 IDxDiagProviderImpl_Initialize,
172 IDxDiagProviderImpl_GetRootContainer
173 };
174
175 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
176 IDxDiagProviderImpl* provider;
177
178 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
179
180 *ppobj = NULL;
181 if (punkOuter) return CLASS_E_NOAGGREGATION;
182
183 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
184 if (NULL == provider) return E_OUTOFMEMORY;
185 provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
186 provider->ref = 0; /* will be inited with QueryInterface */
187 return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
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 fill_processor_information(IDxDiagContainerImpl_Container *node)
547 {
548 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
549
550 static const WCHAR cimv2W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
551 static const WCHAR proc_classW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
552 static const WCHAR nameW[] = {'N','a','m','e',0};
553 static const WCHAR max_clock_speedW[] = {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
554 static const WCHAR cpu_noW[] = {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
555
556 static const WCHAR processor_fmtW[] = {'%','s','(','%','d',' ','C','P','U','s',')',',',' ','~','%','d','M','H','z',0};
557
558 IWbemLocator *wbem_locator;
559 IWbemServices *wbem_service;
560 IWbemClassObject *wbem_class;
561 IEnumWbemClassObject *wbem_enum;
562 VARIANT cpu_name, cpu_no, clock_speed;
563 WCHAR print_buf[200];
564 BSTR bstr;
565 ULONG no;
566 HRESULT hr;
567
568 hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void**)&wbem_locator);
569 if(FAILED(hr))
570 return hr;
571
572 bstr = SysAllocString(cimv2W);
573 if(!bstr) {
574 IWbemLocator_Release(wbem_locator);
575 return E_OUTOFMEMORY;
576 }
577 hr = IWbemLocator_ConnectServer(wbem_locator, bstr, NULL, NULL, NULL, 0, NULL, NULL, &wbem_service);
578 IWbemLocator_Release(wbem_locator);
579 SysFreeString(bstr);
580 if(FAILED(hr))
581 return hr;
582
583 bstr = SysAllocString(proc_classW);
584 if(!bstr) {
585 IWbemServices_Release(wbem_service);
586 return E_OUTOFMEMORY;
587 }
588 hr = IWbemServices_CreateInstanceEnum(wbem_service, bstr, WBEM_FLAG_SYSTEM_ONLY, NULL, &wbem_enum);
589 IWbemServices_Release(wbem_service);
590 SysFreeString(bstr);
591 if(FAILED(hr))
592 return hr;
593
594 hr = IEnumWbemClassObject_Next(wbem_enum, 1000, 1, &wbem_class, &no);
595 IEnumWbemClassObject_Release(wbem_enum);
596 if(FAILED(hr))
597 return hr;
598
599 hr = IWbemClassObject_Get(wbem_class, cpu_noW, 0, &cpu_no, NULL, NULL);
600 if(FAILED(hr)) {
601 IWbemClassObject_Release(wbem_class);
602 return hr;
603 }
604 hr = IWbemClassObject_Get(wbem_class, max_clock_speedW, 0, &clock_speed, NULL, NULL);
605 if(FAILED(hr)) {
606 IWbemClassObject_Release(wbem_class);
607 return hr;
608 }
609 hr = IWbemClassObject_Get(wbem_class, nameW, 0, &cpu_name, NULL, NULL);
610 IWbemClassObject_Release(wbem_class);
611 if(FAILED(hr))
612 return hr;
613
614 sprintfW(print_buf, processor_fmtW, V_BSTR(&cpu_name), V_I4(&cpu_no), V_I4(&clock_speed));
615 VariantClear(&cpu_name);
616 VariantClear(&cpu_no);
617 VariantClear(&clock_speed);
618
619 return add_bstr_property(node, szProcessorEnglish, print_buf);
620 }
621
622 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
623 {
624 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};
625 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};
626 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};
627 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
628 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
629 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
630 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};
631 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
632 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};
633 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};
634 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
635 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
636 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
637 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
638 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
639 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
640 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
641 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
642 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
643 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
644 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};
645 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
646 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
647 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};
648 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};
649 static const WCHAR szSystemManufacturerEnglish[] = {'s','z','S','y','s','t','e','m','M','a','n','u','f','a','c','t','u','r','e','r','E','n','g','l','i','s','h',0};
650 static const WCHAR szSystemModelEnglish[] = {'s','z','S','y','s','t','e','m','M','o','d','e','l','E','n','g','l','i','s','h',0};
651 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
652 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
653 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
654
655 static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
656
657 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};
658 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
659
660 HRESULT hr;
661 MEMORYSTATUSEX msex;
662 OSVERSIONINFOW info;
663 DWORD count, usedpage_mb, availpage_mb;
664 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
665 DWORD_PTR args[2];
666
667 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
668 if (FAILED(hr))
669 return hr;
670
671 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
672 if (FAILED(hr))
673 return hr;
674
675 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
676 if (FAILED(hr))
677 return hr;
678
679 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
680 if (FAILED(hr))
681 return hr;
682
683 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
684 if (FAILED(hr))
685 return hr;
686
687 hr = add_bool_property(node, bDebug, FALSE);
688 if (FAILED(hr))
689 return hr;
690
691 hr = add_bool_property(node, bNECPC98, FALSE);
692 if (FAILED(hr))
693 return hr;
694
695 msex.dwLength = sizeof(msex);
696 GlobalMemoryStatusEx(&msex);
697
698 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
699 if (FAILED(hr))
700 return hr;
701
702 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
703 if (FAILED(hr))
704 return hr;
705
706 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
707 if (FAILED(hr))
708 return hr;
709
710 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
711 if (FAILED(hr))
712 return hr;
713
714 info.dwOSVersionInfoSize = sizeof(info);
715 GetVersionExW(&info);
716
717 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
718 if (FAILED(hr))
719 return hr;
720
721 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
722 if (FAILED(hr))
723 return hr;
724
725 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
726 if (FAILED(hr))
727 return hr;
728
729 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
730 if (FAILED(hr))
731 return hr;
732
733 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
734 if (FAILED(hr))
735 return hr;
736
737 /* FIXME: Roundoff should not be done with truncated division. */
738 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
739 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
740 if (FAILED(hr))
741 return hr;
742
743 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
744 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
745 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
746 args[0] = usedpage_mb;
747 args[1] = availpage_mb;
748 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
749 localized_pagefile_fmt, 0, 0, print_buf,
750 sizeof(print_buf)/sizeof(*print_buf), (__ms_va_list*)args);
751
752 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
753 if (FAILED(hr))
754 return hr;
755
756 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
757
758 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
759 if (FAILED(hr))
760 return hr;
761
762 GetWindowsDirectoryW(buffer, MAX_PATH);
763
764 hr = add_bstr_property(node, szWindowsDir, buffer);
765 if (FAILED(hr))
766 return hr;
767
768 count = sizeof(computer_name)/sizeof(WCHAR);
769 if (!GetComputerNameW(computer_name, &count))
770 return E_FAIL;
771
772 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
773 if (FAILED(hr))
774 return hr;
775
776 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
777 if (FAILED(hr))
778 return hr;
779
780 hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
781 if (FAILED(hr))
782 return hr;
783
784 hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
785 if (FAILED(hr))
786 return hr;
787
788 hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
789 if (FAILED(hr))
790 return hr;
791
792 hr = fill_processor_information(node);
793 if (FAILED(hr))
794 return hr;
795
796 hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
797 if (FAILED(hr))
798 return hr;
799
800 hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
801 if (FAILED(hr))
802 return hr;
803
804 hr = fill_language_information(node);
805 if (FAILED(hr))
806 return hr;
807
808 hr = fill_datetime_information(node);
809 if (FAILED(hr))
810 return hr;
811
812 hr = fill_os_string_information(node, &info);
813 if (FAILED(hr))
814 return hr;
815
816 return S_OK;
817 }
818
819 /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
820 static DWORD depth_for_pixelformat(D3DFORMAT format)
821 {
822 switch (format)
823 {
824 case D3DFMT_P8: return 8;
825 case D3DFMT_X1R5G5B5: return 15;
826 case D3DFMT_R5G6B5: return 16;
827 /* This case will fail to distinguish an original bpp of 24. */
828 case D3DFMT_X8R8G8B8: return 32;
829 default:
830 FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
831 return 32;
832 }
833 }
834
835 static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
836 {
837 IDirectDraw7 *pDirectDraw;
838 HRESULT hr;
839 DDSCAPS2 dd_caps;
840
841 hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
842 if (SUCCEEDED(hr))
843 {
844 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
845 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
846 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
847 IDirectDraw7_Release(pDirectDraw);
848 if (SUCCEEDED(hr))
849 return TRUE;
850 }
851
852 return FALSE;
853 }
854
855 static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
856 {
857 static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
858 static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
859 static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
860 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
861
862 /* Enumeration copied from dlls/wined3d/wined3d_private.h and slightly modified. */
863 enum pci_vendor
864 {
865 HW_VENDOR_AMD = 0x1002,
866 HW_VENDOR_NVIDIA = 0x10de,
867 HW_VENDOR_INTEL = 0x8086,
868 };
869
870 switch (vendor_id)
871 {
872 case HW_VENDOR_AMD:
873 return atiW;
874 case HW_VENDOR_NVIDIA:
875 return nvidiaW;
876 case HW_VENDOR_INTEL:
877 return intelW;
878 default:
879 FIXME("Unknown PCI vendor ID 0x%04x\n", vendor_id);
880 return unknownW;
881 }
882 }
883
884 static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
885 {
886 IDxDiagContainerImpl_Container *display_adapter;
887 HRESULT hr;
888 IDirect3D9 *pDirect3D9;
889 WCHAR buffer[256];
890 UINT index, count;
891
892 pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
893 if (!pDirect3D9)
894 return E_FAIL;
895
896 count = IDirect3D9_GetAdapterCount(pDirect3D9);
897 for (index = 0; index < count; index++)
898 {
899 static const WCHAR adapterid_fmtW[] = {'%','u',0};
900 static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
901 static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
902 static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
903 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
904 static const WCHAR b3DAccelerationExists[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','x','i','s','t','s',0};
905 static const WCHAR b3DAccelerationEnabled[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
906 static const WCHAR bDDAccelerationEnabled[] = {'b','D','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
907
908 D3DADAPTER_IDENTIFIER9 adapter_info;
909 D3DDISPLAYMODE adapter_mode;
910 D3DCAPS9 device_caps;
911 DWORD available_mem = 0;
912 BOOL hardware_accel;
913
914 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), adapterid_fmtW, index);
915 display_adapter = allocate_information_node(buffer);
916 if (!display_adapter)
917 {
918 hr = E_OUTOFMEMORY;
919 goto cleanup;
920 }
921
922 add_subcontainer(node, display_adapter);
923
924 hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
925 if (SUCCEEDED(hr))
926 {
927 WCHAR driverW[sizeof(adapter_info.Driver)];
928 WCHAR descriptionW[sizeof(adapter_info.Description)];
929 WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
930
931 MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, sizeof(driverW)/sizeof(WCHAR));
932 MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW, sizeof(descriptionW)/sizeof(WCHAR));
933 MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW, sizeof(devicenameW)/sizeof(WCHAR));
934
935 hr = add_bstr_property(display_adapter, szDriverName, driverW);
936 if (FAILED(hr))
937 goto cleanup;
938
939 hr = add_bstr_property(display_adapter, szDescription, descriptionW);
940 if (FAILED(hr))
941 goto cleanup;
942
943 hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
944 if (FAILED(hr))
945 goto cleanup;
946
947 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), driverversion_fmtW,
948 HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
949 HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
950
951 hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
952 if (FAILED(hr))
953 goto cleanup;
954
955 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.VendorId);
956 hr = add_bstr_property(display_adapter, szVendorId, buffer);
957 if (FAILED(hr))
958 goto cleanup;
959
960 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.DeviceId);
961 hr = add_bstr_property(display_adapter, szDeviceId, buffer);
962 if (FAILED(hr))
963 goto cleanup;
964
965 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), subsysid_fmtW, adapter_info.SubSysId);
966 hr = add_bstr_property(display_adapter, szSubSysId, buffer);
967 if (FAILED(hr))
968 goto cleanup;
969
970 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.Revision);
971 hr = add_bstr_property(display_adapter, szRevisionId, buffer);
972 if (FAILED(hr))
973 goto cleanup;
974
975 StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
976 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
977 if (FAILED(hr))
978 goto cleanup;
979
980 hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
981 if (FAILED(hr))
982 goto cleanup;
983 }
984
985 hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
986 if (SUCCEEDED(hr))
987 {
988 hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
989 if (FAILED(hr))
990 goto cleanup;
991
992 hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
993 if (FAILED(hr))
994 goto cleanup;
995
996 hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
997 if (FAILED(hr))
998 goto cleanup;
999
1000 hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
1001 if (FAILED(hr))
1002 goto cleanup;
1003 }
1004
1005 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
1006 if (FAILED(hr))
1007 goto cleanup;
1008
1009 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
1010 if (FAILED(hr))
1011 goto cleanup;
1012
1013 hr = add_bstr_property(display_adapter, szChipType, szEmpty);
1014 if (FAILED(hr))
1015 goto cleanup;
1016
1017 hr = add_bstr_property(display_adapter, szDACType, szEmpty);
1018 if (FAILED(hr))
1019 goto cleanup;
1020
1021 hr = add_bstr_property(display_adapter, szRevision, szEmpty);
1022 if (FAILED(hr))
1023 goto cleanup;
1024
1025 if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
1026 WARN("get_texture_memory helper failed\n");
1027
1028 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, available_mem / 1000000.0f);
1029
1030 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1031 if (FAILED(hr))
1032 goto cleanup;
1033
1034 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1035 if (FAILED(hr))
1036 goto cleanup;
1037
1038 hr = IDirect3D9_GetDeviceCaps(pDirect3D9, index, D3DDEVTYPE_HAL, &device_caps);
1039 hardware_accel = SUCCEEDED(hr);
1040
1041 hr = add_bool_property(display_adapter, b3DAccelerationEnabled, hardware_accel);
1042 if (FAILED(hr))
1043 goto cleanup;
1044
1045 hr = add_bool_property(display_adapter, b3DAccelerationExists, hardware_accel);
1046 if (FAILED(hr))
1047 goto cleanup;
1048
1049 hr = add_bool_property(display_adapter, bDDAccelerationEnabled, hardware_accel);
1050 if (FAILED(hr))
1051 goto cleanup;
1052 }
1053
1054 hr = S_OK;
1055 cleanup:
1056 IDirect3D9_Release(pDirect3D9);
1057 return hr;
1058 }
1059
1060 static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
1061 {
1062 static const WCHAR szAdapterID[] = {'0',0};
1063 static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
1064 szKeyDeviceKey, szKeyDeviceID, szDriverName,
1065 szDriverVersion, szSubSysId, szRevisionId,
1066 szManufacturer, szChipType, szDACType, szRevision};
1067
1068 IDxDiagContainerImpl_Container *display_adapter;
1069 HRESULT hr;
1070 IDirectDraw7 *pDirectDraw;
1071 DDSCAPS2 dd_caps;
1072 DISPLAY_DEVICEW disp_dev;
1073 DDSURFACEDESC2 surface_descr;
1074 DWORD tmp;
1075 WCHAR buffer[256];
1076
1077 display_adapter = allocate_information_node(szAdapterID);
1078 if (!display_adapter)
1079 return E_OUTOFMEMORY;
1080
1081 add_subcontainer(node, display_adapter);
1082
1083 disp_dev.cb = sizeof(disp_dev);
1084 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
1085 {
1086 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
1087 if (FAILED(hr))
1088 return hr;
1089
1090 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
1091 if (FAILED(hr))
1092 return hr;
1093 }
1094
1095 /* Silently ignore a failure from DirectDrawCreateEx. */
1096 hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1097 if (FAILED(hr))
1098 return S_OK;
1099
1100 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1101 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
1102 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1103 if (SUCCEEDED(hr))
1104 {
1105 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1106
1107 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, tmp / 1000000.0f);
1108
1109 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1110 if (FAILED(hr))
1111 goto cleanup;
1112
1113 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1114 if (FAILED(hr))
1115 goto cleanup;
1116 }
1117
1118 surface_descr.dwSize = sizeof(surface_descr);
1119 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1120 if (SUCCEEDED(hr))
1121 {
1122 if (surface_descr.dwFlags & DDSD_WIDTH)
1123 {
1124 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1125 if (FAILED(hr))
1126 goto cleanup;
1127 }
1128
1129 if (surface_descr.dwFlags & DDSD_HEIGHT)
1130 {
1131 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1132 if (FAILED(hr))
1133 goto cleanup;
1134 }
1135
1136 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1137 {
1138 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1139 if (FAILED(hr))
1140 goto cleanup;
1141 }
1142 }
1143
1144 hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1145 if (FAILED(hr))
1146 goto cleanup;
1147
1148 for (tmp = 0; tmp < sizeof(empty_properties)/sizeof(empty_properties[0]); tmp++)
1149 {
1150 hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1151 if (FAILED(hr))
1152 goto cleanup;
1153 }
1154
1155 hr = S_OK;
1156 cleanup:
1157 IDirectDraw7_Release(pDirectDraw);
1158 return hr;
1159 }
1160
1161 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1162 {
1163 HRESULT hr;
1164
1165 /* Try to use Direct3D to obtain the required information first. */
1166 hr = fill_display_information_d3d(node);
1167 if (hr != E_FAIL)
1168 return hr;
1169
1170 return fill_display_information_fallback(node);
1171 }
1172
1173 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1174 {
1175 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1176 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};
1177
1178 IDxDiagContainerImpl_Container *cont;
1179
1180 cont = allocate_information_node(DxDiag_SoundDevices);
1181 if (!cont)
1182 return E_OUTOFMEMORY;
1183
1184 add_subcontainer(node, cont);
1185
1186 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1187 if (!cont)
1188 return E_OUTOFMEMORY;
1189
1190 add_subcontainer(node, cont);
1191
1192 return S_OK;
1193 }
1194
1195 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1196 {
1197 return S_OK;
1198 }
1199
1200 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1201 {
1202 return S_OK;
1203 }
1204
1205 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1206 {
1207 return S_OK;
1208 }
1209
1210 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1211 {
1212 return S_OK;
1213 }
1214
1215 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1216 {
1217 static const WCHAR szSlashSep[] = {'\\',0};
1218 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1219 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1220 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1221 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1222 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1223 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1224 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1225 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1226 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1227 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1228
1229 /* Values */
1230 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1231 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1232 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1233
1234 HRESULT hr;
1235 WCHAR *szFile;
1236 WCHAR szVersion_v[1024];
1237 DWORD retval, hdl;
1238 void *pVersionInfo = NULL;
1239 BOOL boolret = FALSE;
1240 UINT uiLength;
1241 VS_FIXEDFILEINFO *pFileInfo;
1242
1243 TRACE("Filling container %p for %s in %s\n", node,
1244 debugstr_w(szFileName), debugstr_w(szFilePath));
1245
1246 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1247 lstrlenW(szFileName) + 2 /* slash + terminator */));
1248 if (!szFile)
1249 return E_OUTOFMEMORY;
1250
1251 lstrcpyW(szFile, szFilePath);
1252 lstrcatW(szFile, szSlashSep);
1253 lstrcatW(szFile, szFileName);
1254
1255 retval = GetFileVersionInfoSizeW(szFile, &hdl);
1256 if (retval)
1257 {
1258 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1259 if (!pVersionInfo)
1260 {
1261 hr = E_OUTOFMEMORY;
1262 goto cleanup;
1263 }
1264
1265 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1266 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1267 boolret = TRUE;
1268 }
1269
1270 hr = add_bstr_property(node, szPath, szFile);
1271 if (FAILED(hr))
1272 goto cleanup;
1273
1274 hr = add_bstr_property(node, szName, szFileName);
1275 if (FAILED(hr))
1276 goto cleanup;
1277
1278 hr = add_bool_property(node, bExists, boolret);
1279 if (FAILED(hr))
1280 goto cleanup;
1281
1282 if (boolret)
1283 {
1284 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
1285 szVersionFormat,
1286 HIWORD(pFileInfo->dwFileVersionMS),
1287 LOWORD(pFileInfo->dwFileVersionMS),
1288 HIWORD(pFileInfo->dwFileVersionLS),
1289 LOWORD(pFileInfo->dwFileVersionLS));
1290
1291 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1292
1293 hr = add_bstr_property(node, szVersion, szVersion_v);
1294 if (FAILED(hr))
1295 goto cleanup;
1296
1297 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1298 if (FAILED(hr))
1299 goto cleanup;
1300
1301 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1302 if (FAILED(hr))
1303 goto cleanup;
1304
1305 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1306 if (FAILED(hr))
1307 goto cleanup;
1308
1309 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1310 if (FAILED(hr))
1311 goto cleanup;
1312
1313 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1314 if (FAILED(hr))
1315 goto cleanup;
1316
1317 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1318 if (FAILED(hr))
1319 goto cleanup;
1320 }
1321
1322 hr = S_OK;
1323 cleanup:
1324 HeapFree(GetProcessHeap(), 0, pVersionInfo);
1325 HeapFree(GetProcessHeap(), 0, szFile);
1326
1327 return hr;
1328 }
1329 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1330 {
1331 static const WCHAR dlls[][15] =
1332 {
1333 {'d','3','d','8','.','d','l','l',0},
1334 {'d','3','d','9','.','d','l','l',0},
1335 {'d','d','r','a','w','.','d','l','l',0},
1336 {'d','e','v','e','n','u','m','.','d','l','l',0},
1337 {'d','i','n','p','u','t','8','.','d','l','l',0},
1338 {'d','i','n','p','u','t','.','d','l','l',0},
1339 {'d','m','b','a','n','d','.','d','l','l',0},
1340 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1341 {'d','m','i','m','e','.','d','l','l',0},
1342 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1343 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1344 {'d','m','s','t','y','l','e','.','d','l','l',0},
1345 {'d','m','s','y','n','t','h','.','d','l','l',0},
1346 {'d','m','u','s','i','c','.','d','l','l',0},
1347 {'d','p','l','a','y','x','.','d','l','l',0},
1348 {'d','p','n','e','t','.','d','l','l',0},
1349 {'d','s','o','u','n','d','.','d','l','l',0},
1350 {'d','s','w','a','v','e','.','d','l','l',0},
1351 {'d','x','d','i','a','g','n','.','d','l','l',0},
1352 {'q','u','a','r','t','z','.','d','l','l',0}
1353 };
1354
1355 HRESULT hr;
1356 WCHAR szFilePath[MAX_PATH];
1357 INT i;
1358
1359 GetSystemDirectoryW(szFilePath, MAX_PATH);
1360
1361 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
1362 {
1363 static const WCHAR szFormat[] = {'%','d',0};
1364
1365 WCHAR szFileID[5];
1366 IDxDiagContainerImpl_Container *file_container;
1367
1368 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
1369
1370 file_container = allocate_information_node(szFileID);
1371 if (!file_container)
1372 return E_OUTOFMEMORY;
1373
1374 hr = fill_file_description(file_container, szFilePath, dlls[i]);
1375 if (FAILED(hr))
1376 {
1377 free_information_tree(file_container);
1378 continue;
1379 }
1380
1381 add_subcontainer(node, file_container);
1382 }
1383
1384 return S_OK;
1385 }
1386
1387 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1388 {
1389 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1390 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1391
1392 HRESULT hr;
1393
1394 VariantInit(friendly_name);
1395 VariantInit(clsid_name);
1396
1397 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1398 if (FAILED(hr))
1399 return hr;
1400
1401 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1402 if (FAILED(hr))
1403 {
1404 VariantClear(friendly_name);
1405 return hr;
1406 }
1407
1408 return S_OK;
1409 }
1410
1411 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1412 {
1413 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1414 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1415 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1416 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1417 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1418
1419 HRESULT hr;
1420 IFilterMapper2 *pFileMapper = NULL;
1421 IAMFilterData *pFilterData = NULL;
1422 BYTE *ppRF = NULL;
1423 REGFILTER2 *pRF = NULL;
1424 WCHAR bufferW[10];
1425 ULONG j;
1426 DWORD dwNOutputs = 0;
1427 DWORD dwNInputs = 0;
1428
1429 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1430 (void **)&pFileMapper);
1431 if (FAILED(hr))
1432 return hr;
1433
1434 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1435 if (FAILED(hr))
1436 goto cleanup;
1437
1438 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&ppRF);
1439 if (FAILED(hr))
1440 goto cleanup;
1441 pRF = ((REGFILTER2**)ppRF)[0];
1442
1443 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1444 hr = add_bstr_property(subcont, szVersionW, bufferW);
1445 if (FAILED(hr))
1446 goto cleanup;
1447
1448 if (pRF->dwVersion == 1)
1449 {
1450 for (j = 0; j < pRF->u.s1.cPins; j++)
1451 if (pRF->u.s1.rgPins[j].bOutput)
1452 dwNOutputs++;
1453 else
1454 dwNInputs++;
1455 }
1456 else if (pRF->dwVersion == 2)
1457 {
1458 for (j = 0; j < pRF->u.s2.cPins2; j++)
1459 if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1460 dwNOutputs++;
1461 else
1462 dwNInputs++;
1463 }
1464
1465 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1466 if (FAILED(hr))
1467 goto cleanup;
1468
1469 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1470 if (FAILED(hr))
1471 goto cleanup;
1472
1473 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1474 if (FAILED(hr))
1475 goto cleanup;
1476
1477 hr = S_OK;
1478 cleanup:
1479 CoTaskMemFree(pRF);
1480 if (pFilterData) IAMFilterData_Release(pFilterData);
1481 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1482
1483 return hr;
1484 }
1485
1486 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1487 {
1488 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1489 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1490 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1491
1492 HRESULT hr;
1493 IPropertyBag *pPropFilterBag = NULL;
1494 BYTE *pData;
1495 VARIANT friendly_name;
1496 VARIANT clsid_name;
1497 VARIANT v;
1498
1499 VariantInit(&friendly_name);
1500 VariantInit(&clsid_name);
1501 VariantInit(&v);
1502
1503 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1504 if (FAILED(hr))
1505 return hr;
1506
1507 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1508 if (FAILED(hr))
1509 goto cleanup;
1510
1511 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1512 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1513
1514 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1515 if (FAILED(hr))
1516 goto cleanup;
1517
1518 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1519 if (FAILED(hr))
1520 goto cleanup;
1521
1522 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1523 if (FAILED(hr))
1524 goto cleanup;
1525
1526 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1527 if (FAILED(hr))
1528 goto cleanup;
1529
1530 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1531 SafeArrayUnaccessData(V_ARRAY(&v));
1532 if (FAILED(hr))
1533 goto cleanup;
1534
1535 hr = S_OK;
1536 cleanup:
1537 VariantClear(&v);
1538 VariantClear(&clsid_name);
1539 VariantClear(&friendly_name);
1540 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1541
1542 return hr;
1543 }
1544
1545 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1546 {
1547 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1548 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1549 static const WCHAR szIdFormat[] = {'%','d',0};
1550
1551 HRESULT hr;
1552 int i = 0;
1553 ICreateDevEnum *pCreateDevEnum;
1554 IEnumMoniker *pEmCat = NULL;
1555 IMoniker *pMCat = NULL;
1556 IEnumMoniker *pEnum = NULL;
1557
1558 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1559 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1560 if (FAILED(hr))
1561 return hr;
1562
1563 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1564 if (FAILED(hr))
1565 goto cleanup;
1566
1567 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1568 {
1569 VARIANT vCatName;
1570 VARIANT vCatClsid;
1571 IPropertyBag *pPropBag;
1572 CLSID clsidCat;
1573 IMoniker *pMoniker = NULL;
1574
1575 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1576 if (FAILED(hr))
1577 {
1578 IMoniker_Release(pMCat);
1579 break;
1580 }
1581
1582 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1583 IPropertyBag_Release(pPropBag);
1584 if (FAILED(hr))
1585 {
1586 IMoniker_Release(pMCat);
1587 break;
1588 }
1589
1590 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1591 if (FAILED(hr))
1592 {
1593 IMoniker_Release(pMCat);
1594 VariantClear(&vCatClsid);
1595 VariantClear(&vCatName);
1596 break;
1597 }
1598
1599 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1600 if (hr != S_OK)
1601 {
1602 IMoniker_Release(pMCat);
1603 VariantClear(&vCatClsid);
1604 VariantClear(&vCatName);
1605 continue;
1606 }
1607
1608 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1609
1610 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1611 {
1612 WCHAR bufferW[10];
1613 IDxDiagContainerImpl_Container *subcont;
1614
1615 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1616 subcont = allocate_information_node(bufferW);
1617 if (!subcont)
1618 {
1619 hr = E_OUTOFMEMORY;
1620 IMoniker_Release(pMoniker);
1621 break;
1622 }
1623
1624 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1625 if (FAILED(hr))
1626 {
1627 free_information_tree(subcont);
1628 IMoniker_Release(pMoniker);
1629 break;
1630 }
1631
1632 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1633 if (FAILED(hr))
1634 {
1635 free_information_tree(subcont);
1636 IMoniker_Release(pMoniker);
1637 break;
1638 }
1639
1640 hr = fill_filter_container(subcont, pMoniker);
1641 IMoniker_Release(pMoniker);
1642 if (FAILED(hr))
1643 {
1644 WARN("Skipping invalid filter\n");
1645 free_information_tree(subcont);
1646 hr = S_OK;
1647 continue;
1648 }
1649
1650 add_subcontainer(node, subcont);
1651 i++;
1652 }
1653
1654 IEnumMoniker_Release(pEnum);
1655 IMoniker_Release(pMCat);
1656 VariantClear(&vCatClsid);
1657 VariantClear(&vCatName);
1658
1659 if (FAILED(hr))
1660 break;
1661 }
1662
1663 cleanup:
1664 if (pEmCat) IEnumMoniker_Release(pEmCat);
1665 ICreateDevEnum_Release(pCreateDevEnum);
1666 return hr;
1667 }
1668
1669 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1670 {
1671 return S_OK;
1672 }
1673
1674 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1675 {
1676 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1677 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};
1678 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1679 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1680 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1681 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1682 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};
1683 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1684 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};
1685 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1686
1687 static const struct
1688 {
1689 const WCHAR *name;
1690 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1691 } root_children[] =
1692 {
1693 {DxDiag_SystemInfo, build_systeminfo_tree},
1694 {DxDiag_DisplayDevices, build_displaydevices_tree},
1695 {DxDiag_DirectSound, build_directsound_tree},
1696 {DxDiag_DirectMusic, build_directmusic_tree},
1697 {DxDiag_DirectInput, build_directinput_tree},
1698 {DxDiag_DirectPlay, build_directplay_tree},
1699 {DxDiag_SystemDevices, build_systemdevices_tree},
1700 {DxDiag_DirectXFiles, build_directxfiles_tree},
1701 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1702 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1703 };
1704
1705 IDxDiagContainerImpl_Container *info_root;
1706 size_t index;
1707
1708 info_root = allocate_information_node(NULL);
1709 if (!info_root)
1710 return E_OUTOFMEMORY;
1711
1712 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1713 {
1714 IDxDiagContainerImpl_Container *node;
1715 HRESULT hr;
1716
1717 node = allocate_information_node(root_children[index].name);
1718 if (!node)
1719 {
1720 free_information_tree(info_root);
1721 return E_OUTOFMEMORY;
1722 }
1723
1724 hr = root_children[index].initfunc(node);
1725 if (FAILED(hr))
1726 {
1727 free_information_tree(node);
1728 free_information_tree(info_root);
1729 return hr;
1730 }
1731
1732 add_subcontainer(info_root, node);
1733 }
1734
1735 *pinfo_root = info_root;
1736 return S_OK;
1737 }