[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
56 struct IDxDiagProviderImpl
57 {
58 IDxDiagProvider IDxDiagProvider_iface;
59 LONG ref;
60 BOOL init;
61 DXDIAG_INIT_PARAMS params;
62 IDxDiagContainerImpl_Container *info_root;
63 };
64
65 static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
66 {
67 return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
68 }
69
70 /* IDxDiagProvider IUnknown parts follow: */
71 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
72 void **ppobj)
73 {
74 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
75
76 if (!ppobj) return E_INVALIDARG;
77
78 if (IsEqualGUID(riid, &IID_IUnknown)
79 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
80 IUnknown_AddRef(iface);
81 *ppobj = This;
82 return S_OK;
83 }
84
85 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
86 *ppobj = NULL;
87 return E_NOINTERFACE;
88 }
89
90 static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
91 {
92 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
93 ULONG refCount = InterlockedIncrement(&This->ref);
94
95 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
96
97 DXDIAGN_LockModule();
98
99 return refCount;
100 }
101
102 static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
103 {
104 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
105 ULONG refCount = InterlockedDecrement(&This->ref);
106
107 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
108
109 if (!refCount) {
110 free_information_tree(This->info_root);
111 HeapFree(GetProcessHeap(), 0, This);
112 }
113
114 DXDIAGN_UnlockModule();
115
116 return refCount;
117 }
118
119 /* IDxDiagProvider Interface follow: */
120 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
121 DXDIAG_INIT_PARAMS *pParams)
122 {
123 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
124 HRESULT hr;
125
126 TRACE("(%p,%p)\n", iface, pParams);
127
128 if (NULL == pParams) {
129 return E_POINTER;
130 }
131 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
132 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
133 return E_INVALIDARG;
134 }
135
136 if (!This->info_root)
137 {
138 hr = build_information_tree(&This->info_root);
139 if (FAILED(hr))
140 return hr;
141 }
142
143 This->init = TRUE;
144 memcpy(&This->params, pParams, pParams->dwSize);
145 return S_OK;
146 }
147
148 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
149 IDxDiagContainer **ppInstance)
150 {
151 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
152
153 TRACE("(%p,%p)\n", iface, ppInstance);
154
155 if (FALSE == This->init) {
156 return CO_E_NOTINITIALIZED;
157 }
158
159 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
160 &This->IDxDiagProvider_iface, (void **)ppInstance);
161 }
162
163 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
164 {
165 IDxDiagProviderImpl_QueryInterface,
166 IDxDiagProviderImpl_AddRef,
167 IDxDiagProviderImpl_Release,
168 IDxDiagProviderImpl_Initialize,
169 IDxDiagProviderImpl_GetRootContainer
170 };
171
172 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
173 IDxDiagProviderImpl* provider;
174
175 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
176
177 *ppobj = NULL;
178 if (punkOuter) return CLASS_E_NOAGGREGATION;
179
180 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
181 if (NULL == provider) return E_OUTOFMEMORY;
182 provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
183 provider->ref = 0; /* will be inited with QueryInterface */
184 return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
185 }
186
187 static void free_property_information(IDxDiagContainerImpl_Property *prop)
188 {
189 VariantClear(&prop->vProp);
190 HeapFree(GetProcessHeap(), 0, prop->propName);
191 HeapFree(GetProcessHeap(), 0, prop);
192 }
193
194 static void free_information_tree(IDxDiagContainerImpl_Container *node)
195 {
196 IDxDiagContainerImpl_Container *ptr, *cursor2;
197
198 if (!node)
199 return;
200
201 HeapFree(GetProcessHeap(), 0, node->contName);
202
203 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
204 {
205 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
206
207 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
208 {
209 list_remove(&prop->entry);
210 free_property_information(prop);
211 }
212
213 list_remove(&ptr->entry);
214 free_information_tree(ptr);
215 }
216
217 HeapFree(GetProcessHeap(), 0, node);
218 }
219
220 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
221 {
222 IDxDiagContainerImpl_Container *ret;
223
224 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
225 if (!ret)
226 return NULL;
227
228 if (name)
229 {
230 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
231 if (!ret->contName)
232 {
233 HeapFree(GetProcessHeap(), 0, ret);
234 return NULL;
235 }
236 strcpyW(ret->contName, name);
237 }
238
239 list_init(&ret->subContainers);
240 list_init(&ret->properties);
241
242 return ret;
243 }
244
245 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
246 {
247 IDxDiagContainerImpl_Property *ret;
248
249 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
250 if (!ret)
251 return NULL;
252
253 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
254 if (!ret->propName)
255 {
256 HeapFree(GetProcessHeap(), 0, ret);
257 return NULL;
258 }
259 strcpyW(ret->propName, name);
260
261 return ret;
262 }
263
264 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
265 {
266 list_add_tail(&node->subContainers, &subCont->entry);
267 ++node->nSubContainers;
268 }
269
270 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
271 {
272 IDxDiagContainerImpl_Property *prop;
273 BSTR bstr;
274
275 prop = allocate_property_information(propName);
276 if (!prop)
277 return E_OUTOFMEMORY;
278
279 bstr = SysAllocString(str);
280 if (!bstr)
281 {
282 free_property_information(prop);
283 return E_OUTOFMEMORY;
284 }
285
286 V_VT(&prop->vProp) = VT_BSTR;
287 V_BSTR(&prop->vProp) = bstr;
288
289 list_add_tail(&node->properties, &prop->entry);
290 ++node->nProperties;
291
292 return S_OK;
293 }
294
295 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
296 {
297 IDxDiagContainerImpl_Property *prop;
298
299 prop = allocate_property_information(propName);
300 if (!prop)
301 return E_OUTOFMEMORY;
302
303 V_VT(&prop->vProp) = VT_UI4;
304 V_UI4(&prop->vProp) = data;
305
306 list_add_tail(&node->properties, &prop->entry);
307 ++node->nProperties;
308
309 return S_OK;
310 }
311
312 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
313 {
314 IDxDiagContainerImpl_Property *prop;
315
316 prop = allocate_property_information(propName);
317 if (!prop)
318 return E_OUTOFMEMORY;
319
320 V_VT(&prop->vProp) = VT_BOOL;
321 V_BOOL(&prop->vProp) = data;
322
323 list_add_tail(&node->properties, &prop->entry);
324 ++node->nProperties;
325
326 return S_OK;
327 }
328
329 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
330 {
331 IDxDiagContainerImpl_Property *prop;
332
333 prop = allocate_property_information(propName);
334 if (!prop)
335 return E_OUTOFMEMORY;
336
337 V_VT(&prop->vProp) = VT_UI8;
338 V_UI8(&prop->vProp) = data;
339
340 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
341
342 list_add_tail(&node->properties, &prop->entry);
343 ++node->nProperties;
344
345 return S_OK;
346 }
347
348 /* Copied from programs/taskkill/taskkill.c. */
349 static DWORD *enumerate_processes(DWORD *list_count)
350 {
351 DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
352
353 pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
354 if (!pid_list)
355 return NULL;
356
357 for (;;)
358 {
359 DWORD *realloc_list;
360
361 if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
362 {
363 HeapFree(GetProcessHeap(), 0, pid_list);
364 return NULL;
365 }
366
367 /* EnumProcesses can't signal an insufficient buffer condition, so the
368 * only way to possibly determine whether a larger buffer is required
369 * is to see whether the written number of bytes is the same as the
370 * buffer size. If so, the buffer will be reallocated to twice the
371 * size. */
372 if (alloc_bytes != needed_bytes)
373 break;
374
375 alloc_bytes *= 2;
376 realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
377 if (!realloc_list)
378 {
379 HeapFree(GetProcessHeap(), 0, pid_list);
380 return NULL;
381 }
382 pid_list = realloc_list;
383 }
384
385 *list_count = needed_bytes / sizeof(*pid_list);
386 return pid_list;
387 }
388
389 /* Copied from programs/taskkill/taskkill.c. */
390 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
391 {
392 HANDLE process;
393 HMODULE module;
394 DWORD required_size;
395
396 process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
397 if (!process)
398 return FALSE;
399
400 if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
401 {
402 CloseHandle(process);
403 return FALSE;
404 }
405
406 if (!GetModuleBaseNameW(process, module, buf, chars))
407 {
408 CloseHandle(process);
409 return FALSE;
410 }
411
412 CloseHandle(process);
413 return TRUE;
414 }
415
416 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
417 static BOOL is_netmeeting_running(void)
418 {
419 static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
420
421 DWORD list_count;
422 DWORD *pid_list = enumerate_processes(&list_count);
423
424 if (pid_list)
425 {
426 DWORD i;
427 WCHAR process_name[MAX_PATH];
428
429 for (i = 0; i < list_count; i++)
430 {
431 if (get_process_name_from_pid(pid_list[i], process_name, sizeof(process_name)/sizeof(WCHAR)) &&
432 !lstrcmpW(conf_exe, process_name))
433 {
434 HeapFree(GetProcessHeap(), 0, pid_list);
435 return TRUE;
436 }
437 }
438 HeapFree(GetProcessHeap(), 0, pid_list);
439 }
440
441 return FALSE;
442 }
443
444 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
445 {
446 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
447 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
448 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};
449 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
450
451 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
452 HRESULT hr;
453
454 /* szLanguagesLocalized */
455 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
456 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
457 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
458
459 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
460
461 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
462 if (FAILED(hr))
463 return hr;
464
465 /* szLanguagesEnglish */
466 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
467 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
468
469 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
470
471 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
472 if (FAILED(hr))
473 return hr;
474
475 return S_OK;
476 }
477
478 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
479 {
480 static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
481 static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
482 static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
483 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
484 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
485
486 SYSTEMTIME curtime;
487 WCHAR date_str[80], time_str[80], datetime_str[200];
488 HRESULT hr;
489
490 GetLocalTime(&curtime);
491
492 GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, sizeof(time_str)/sizeof(WCHAR));
493
494 /* szTimeLocalized */
495 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, sizeof(date_str)/sizeof(WCHAR));
496
497 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
498
499 hr = add_bstr_property(node, szTimeLocalized, datetime_str);
500 if (FAILED(hr))
501 return hr;
502
503 /* szTimeEnglish */
504 GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, sizeof(date_str)/sizeof(WCHAR));
505
506 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
507
508 hr = add_bstr_property(node, szTimeEnglish, datetime_str);
509 if (FAILED(hr))
510 return hr;
511
512 return S_OK;
513 }
514
515 static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
516 {
517 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};
518 static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
519 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
520 static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
521 static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
522 static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
523 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
524
525 static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
526 szOSEnglish, szOSExEnglish, szOSExLongEnglish};
527
528 size_t i;
529 HRESULT hr;
530
531 /* FIXME: OS detection should be performed, and localized OS strings
532 * should contain translated versions of the "build" phrase. */
533 for (i = 0; i < sizeof(prop_list)/sizeof(prop_list[0]); i++)
534 {
535 hr = add_bstr_property(node, prop_list[i], winxpW);
536 if (FAILED(hr))
537 return hr;
538 }
539
540 return S_OK;
541 }
542
543 static HRESULT fill_processor_information(IDxDiagContainerImpl_Container *node)
544 {
545 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
546
547 static const WCHAR cimv2W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
548 static const WCHAR proc_classW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
549 static const WCHAR nameW[] = {'N','a','m','e',0};
550 static const WCHAR max_clock_speedW[] = {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
551 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};
552
553 static const WCHAR processor_fmtW[] = {'%','s','(','%','d',' ','C','P','U','s',')',',',' ','~','%','d','M','H','z',0};
554
555 IWbemLocator *wbem_locator;
556 IWbemServices *wbem_service;
557 IWbemClassObject *wbem_class;
558 IEnumWbemClassObject *wbem_enum;
559 VARIANT cpu_name, cpu_no, clock_speed;
560 WCHAR print_buf[200];
561 BSTR bstr;
562 ULONG no;
563 HRESULT hr;
564
565 hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void**)&wbem_locator);
566 if(FAILED(hr))
567 return hr;
568
569 bstr = SysAllocString(cimv2W);
570 if(!bstr) {
571 IWbemLocator_Release(wbem_locator);
572 return E_OUTOFMEMORY;
573 }
574 hr = IWbemLocator_ConnectServer(wbem_locator, bstr, NULL, NULL, NULL, 0, NULL, NULL, &wbem_service);
575 IWbemLocator_Release(wbem_locator);
576 SysFreeString(bstr);
577 if(FAILED(hr))
578 return hr;
579
580 bstr = SysAllocString(proc_classW);
581 if(!bstr) {
582 IWbemServices_Release(wbem_service);
583 return E_OUTOFMEMORY;
584 }
585 hr = IWbemServices_CreateInstanceEnum(wbem_service, bstr, WBEM_FLAG_SYSTEM_ONLY, NULL, &wbem_enum);
586 IWbemServices_Release(wbem_service);
587 SysFreeString(bstr);
588 if(FAILED(hr))
589 return hr;
590
591 hr = IEnumWbemClassObject_Next(wbem_enum, 1000, 1, &wbem_class, &no);
592 IEnumWbemClassObject_Release(wbem_enum);
593 if(FAILED(hr))
594 return hr;
595
596 hr = IWbemClassObject_Get(wbem_class, cpu_noW, 0, &cpu_no, NULL, NULL);
597 if(FAILED(hr)) {
598 IWbemClassObject_Release(wbem_class);
599 return hr;
600 }
601 hr = IWbemClassObject_Get(wbem_class, max_clock_speedW, 0, &clock_speed, NULL, NULL);
602 if(FAILED(hr)) {
603 IWbemClassObject_Release(wbem_class);
604 return hr;
605 }
606 hr = IWbemClassObject_Get(wbem_class, nameW, 0, &cpu_name, NULL, NULL);
607 IWbemClassObject_Release(wbem_class);
608 if(FAILED(hr))
609 return hr;
610
611 sprintfW(print_buf, processor_fmtW, V_BSTR(&cpu_name), V_I4(&cpu_no), V_I4(&clock_speed));
612 VariantClear(&cpu_name);
613 VariantClear(&cpu_no);
614 VariantClear(&clock_speed);
615
616 return add_bstr_property(node, szProcessorEnglish, print_buf);
617 }
618
619 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
620 {
621 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};
622 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};
623 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};
624 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
625 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
626 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
627 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};
628 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
629 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};
630 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};
631 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
632 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
633 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
634 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
635 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
636 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
637 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
638 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
639 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
640 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
641 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};
642 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
643 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
644 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};
645 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};
646 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};
647 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};
648 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
649 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
650 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
651
652 static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
653
654 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};
655 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
656
657 HRESULT hr;
658 MEMORYSTATUSEX msex;
659 OSVERSIONINFOW info;
660 DWORD count, usedpage_mb, availpage_mb;
661 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
662 DWORD_PTR args[2];
663
664 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
665 if (FAILED(hr))
666 return hr;
667
668 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
669 if (FAILED(hr))
670 return hr;
671
672 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
673 if (FAILED(hr))
674 return hr;
675
676 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
677 if (FAILED(hr))
678 return hr;
679
680 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
681 if (FAILED(hr))
682 return hr;
683
684 hr = add_bool_property(node, bDebug, FALSE);
685 if (FAILED(hr))
686 return hr;
687
688 hr = add_bool_property(node, bNECPC98, FALSE);
689 if (FAILED(hr))
690 return hr;
691
692 msex.dwLength = sizeof(msex);
693 GlobalMemoryStatusEx(&msex);
694
695 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
696 if (FAILED(hr))
697 return hr;
698
699 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
700 if (FAILED(hr))
701 return hr;
702
703 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
704 if (FAILED(hr))
705 return hr;
706
707 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
708 if (FAILED(hr))
709 return hr;
710
711 info.dwOSVersionInfoSize = sizeof(info);
712 GetVersionExW(&info);
713
714 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
715 if (FAILED(hr))
716 return hr;
717
718 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
719 if (FAILED(hr))
720 return hr;
721
722 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
723 if (FAILED(hr))
724 return hr;
725
726 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
727 if (FAILED(hr))
728 return hr;
729
730 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
731 if (FAILED(hr))
732 return hr;
733
734 /* FIXME: Roundoff should not be done with truncated division. */
735 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
736 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
737 if (FAILED(hr))
738 return hr;
739
740 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
741 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
742 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
743 args[0] = usedpage_mb;
744 args[1] = availpage_mb;
745 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
746 localized_pagefile_fmt, 0, 0, print_buf,
747 sizeof(print_buf)/sizeof(*print_buf), (__ms_va_list*)args);
748
749 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
750 if (FAILED(hr))
751 return hr;
752
753 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
754
755 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
756 if (FAILED(hr))
757 return hr;
758
759 GetWindowsDirectoryW(buffer, MAX_PATH);
760
761 hr = add_bstr_property(node, szWindowsDir, buffer);
762 if (FAILED(hr))
763 return hr;
764
765 count = sizeof(computer_name)/sizeof(WCHAR);
766 if (!GetComputerNameW(computer_name, &count))
767 return E_FAIL;
768
769 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
770 if (FAILED(hr))
771 return hr;
772
773 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
774 if (FAILED(hr))
775 return hr;
776
777 hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
778 if (FAILED(hr))
779 return hr;
780
781 hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
782 if (FAILED(hr))
783 return hr;
784
785 hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
786 if (FAILED(hr))
787 return hr;
788
789 hr = fill_processor_information(node);
790 if (FAILED(hr))
791 return hr;
792
793 hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
794 if (FAILED(hr))
795 return hr;
796
797 hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
798 if (FAILED(hr))
799 return hr;
800
801 hr = fill_language_information(node);
802 if (FAILED(hr))
803 return hr;
804
805 hr = fill_datetime_information(node);
806 if (FAILED(hr))
807 return hr;
808
809 hr = fill_os_string_information(node, &info);
810 if (FAILED(hr))
811 return hr;
812
813 return S_OK;
814 }
815
816 /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
817 static DWORD depth_for_pixelformat(D3DFORMAT format)
818 {
819 switch (format)
820 {
821 case D3DFMT_P8: return 8;
822 case D3DFMT_X1R5G5B5: return 15;
823 case D3DFMT_R5G6B5: return 16;
824 /* This case will fail to distinguish an original bpp of 24. */
825 case D3DFMT_X8R8G8B8: return 32;
826 default:
827 FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
828 return 32;
829 }
830 }
831
832 static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
833 {
834 IDirectDraw7 *pDirectDraw;
835 HRESULT hr;
836 DDSCAPS2 dd_caps;
837
838 hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
839 if (SUCCEEDED(hr))
840 {
841 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
842 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
843 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
844 IDirectDraw7_Release(pDirectDraw);
845 if (SUCCEEDED(hr))
846 return TRUE;
847 }
848
849 return FALSE;
850 }
851
852 static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
853 {
854 static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
855 static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
856 static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
857 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
858
859 /* Enumeration copied from dlls/wined3d/wined3d_private.h and slightly modified. */
860 enum pci_vendor
861 {
862 HW_VENDOR_AMD = 0x1002,
863 HW_VENDOR_NVIDIA = 0x10de,
864 HW_VENDOR_INTEL = 0x8086,
865 };
866
867 switch (vendor_id)
868 {
869 case HW_VENDOR_AMD:
870 return atiW;
871 case HW_VENDOR_NVIDIA:
872 return nvidiaW;
873 case HW_VENDOR_INTEL:
874 return intelW;
875 default:
876 FIXME("Unknown PCI vendor ID 0x%04x\n", vendor_id);
877 return unknownW;
878 }
879 }
880
881 static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
882 {
883 IDxDiagContainerImpl_Container *display_adapter;
884 HRESULT hr;
885 IDirect3D9 *pDirect3D9;
886 WCHAR buffer[256];
887 UINT index, count;
888
889 pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
890 if (!pDirect3D9)
891 return E_FAIL;
892
893 count = IDirect3D9_GetAdapterCount(pDirect3D9);
894 for (index = 0; index < count; index++)
895 {
896 static const WCHAR adapterid_fmtW[] = {'%','u',0};
897 static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
898 static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
899 static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
900 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
901
902 D3DADAPTER_IDENTIFIER9 adapter_info;
903 D3DDISPLAYMODE adapter_mode;
904 DWORD available_mem = 0;
905
906 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), adapterid_fmtW, index);
907 display_adapter = allocate_information_node(buffer);
908 if (!display_adapter)
909 {
910 hr = E_OUTOFMEMORY;
911 goto cleanup;
912 }
913
914 add_subcontainer(node, display_adapter);
915
916 hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
917 if (SUCCEEDED(hr))
918 {
919 WCHAR driverW[sizeof(adapter_info.Driver)];
920 WCHAR descriptionW[sizeof(adapter_info.Description)];
921 WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
922
923 MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, sizeof(driverW)/sizeof(WCHAR));
924 MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW, sizeof(descriptionW)/sizeof(WCHAR));
925 MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW, sizeof(devicenameW)/sizeof(WCHAR));
926
927 hr = add_bstr_property(display_adapter, szDriverName, driverW);
928 if (FAILED(hr))
929 goto cleanup;
930
931 hr = add_bstr_property(display_adapter, szDescription, descriptionW);
932 if (FAILED(hr))
933 goto cleanup;
934
935 hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
936 if (FAILED(hr))
937 goto cleanup;
938
939 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), driverversion_fmtW,
940 HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
941 HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
942
943 hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
944 if (FAILED(hr))
945 goto cleanup;
946
947 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.VendorId);
948 hr = add_bstr_property(display_adapter, szVendorId, buffer);
949 if (FAILED(hr))
950 goto cleanup;
951
952 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.DeviceId);
953 hr = add_bstr_property(display_adapter, szDeviceId, buffer);
954 if (FAILED(hr))
955 goto cleanup;
956
957 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), subsysid_fmtW, adapter_info.SubSysId);
958 hr = add_bstr_property(display_adapter, szSubSysId, buffer);
959 if (FAILED(hr))
960 goto cleanup;
961
962 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.Revision);
963 hr = add_bstr_property(display_adapter, szRevisionId, buffer);
964 if (FAILED(hr))
965 goto cleanup;
966
967 StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
968 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
969 if (FAILED(hr))
970 goto cleanup;
971
972 hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
973 if (FAILED(hr))
974 goto cleanup;
975 }
976
977 hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
978 if (SUCCEEDED(hr))
979 {
980 hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
981 if (FAILED(hr))
982 goto cleanup;
983
984 hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
985 if (FAILED(hr))
986 goto cleanup;
987
988 hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
989 if (FAILED(hr))
990 goto cleanup;
991
992 hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
993 if (FAILED(hr))
994 goto cleanup;
995 }
996
997 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
998 if (FAILED(hr))
999 goto cleanup;
1000
1001 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
1002 if (FAILED(hr))
1003 goto cleanup;
1004
1005 if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
1006 WARN("get_texture_memory helper failed\n");
1007
1008 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, available_mem / 1000000.0f);
1009
1010 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1011 if (FAILED(hr))
1012 goto cleanup;
1013
1014 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1015 if (FAILED(hr))
1016 goto cleanup;
1017 }
1018
1019 hr = S_OK;
1020 cleanup:
1021 IDirect3D9_Release(pDirect3D9);
1022 return hr;
1023 }
1024
1025 static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
1026 {
1027 static const WCHAR szAdapterID[] = {'0',0};
1028 static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
1029 szKeyDeviceKey, szKeyDeviceID, szDriverName,
1030 szDriverVersion, szSubSysId, szRevisionId,
1031 szManufacturer};
1032
1033 IDxDiagContainerImpl_Container *display_adapter;
1034 HRESULT hr;
1035 IDirectDraw7 *pDirectDraw;
1036 DDSCAPS2 dd_caps;
1037 DISPLAY_DEVICEW disp_dev;
1038 DDSURFACEDESC2 surface_descr;
1039 DWORD tmp;
1040 WCHAR buffer[256];
1041
1042 display_adapter = allocate_information_node(szAdapterID);
1043 if (!display_adapter)
1044 return E_OUTOFMEMORY;
1045
1046 add_subcontainer(node, display_adapter);
1047
1048 disp_dev.cb = sizeof(disp_dev);
1049 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
1050 {
1051 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
1052 if (FAILED(hr))
1053 return hr;
1054
1055 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
1056 if (FAILED(hr))
1057 return hr;
1058 }
1059
1060 /* Silently ignore a failure from DirectDrawCreateEx. */
1061 hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1062 if (FAILED(hr))
1063 return S_OK;
1064
1065 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1066 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
1067 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1068 if (SUCCEEDED(hr))
1069 {
1070 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1071
1072 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, tmp / 1000000.0f);
1073
1074 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1075 if (FAILED(hr))
1076 goto cleanup;
1077
1078 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1079 if (FAILED(hr))
1080 goto cleanup;
1081 }
1082
1083 surface_descr.dwSize = sizeof(surface_descr);
1084 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1085 if (SUCCEEDED(hr))
1086 {
1087 if (surface_descr.dwFlags & DDSD_WIDTH)
1088 {
1089 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1090 if (FAILED(hr))
1091 goto cleanup;
1092 }
1093
1094 if (surface_descr.dwFlags & DDSD_HEIGHT)
1095 {
1096 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1097 if (FAILED(hr))
1098 goto cleanup;
1099 }
1100
1101 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1102 {
1103 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1104 if (FAILED(hr))
1105 goto cleanup;
1106 }
1107 }
1108
1109 hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1110 if (FAILED(hr))
1111 goto cleanup;
1112
1113 for (tmp = 0; tmp < sizeof(empty_properties)/sizeof(empty_properties[0]); tmp++)
1114 {
1115 hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1116 if (FAILED(hr))
1117 goto cleanup;
1118 }
1119
1120 hr = S_OK;
1121 cleanup:
1122 IDirectDraw7_Release(pDirectDraw);
1123 return hr;
1124 }
1125
1126 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1127 {
1128 HRESULT hr;
1129
1130 /* Try to use Direct3D to obtain the required information first. */
1131 hr = fill_display_information_d3d(node);
1132 if (hr != E_FAIL)
1133 return hr;
1134
1135 return fill_display_information_fallback(node);
1136 }
1137
1138 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1139 {
1140 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1141 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};
1142
1143 IDxDiagContainerImpl_Container *cont;
1144
1145 cont = allocate_information_node(DxDiag_SoundDevices);
1146 if (!cont)
1147 return E_OUTOFMEMORY;
1148
1149 add_subcontainer(node, cont);
1150
1151 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1152 if (!cont)
1153 return E_OUTOFMEMORY;
1154
1155 add_subcontainer(node, cont);
1156
1157 return S_OK;
1158 }
1159
1160 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1161 {
1162 return S_OK;
1163 }
1164
1165 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1166 {
1167 return S_OK;
1168 }
1169
1170 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1171 {
1172 return S_OK;
1173 }
1174
1175 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1176 {
1177 return S_OK;
1178 }
1179
1180 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1181 {
1182 static const WCHAR szSlashSep[] = {'\\',0};
1183 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1184 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1185 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1186 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1187 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1188 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1189 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1190 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1191 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1192 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1193
1194 /* Values */
1195 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1196 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1197 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1198
1199 HRESULT hr;
1200 WCHAR *szFile;
1201 WCHAR szVersion_v[1024];
1202 DWORD retval, hdl;
1203 void *pVersionInfo = NULL;
1204 BOOL boolret = FALSE;
1205 UINT uiLength;
1206 VS_FIXEDFILEINFO *pFileInfo;
1207
1208 TRACE("Filling container %p for %s in %s\n", node,
1209 debugstr_w(szFileName), debugstr_w(szFilePath));
1210
1211 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1212 lstrlenW(szFileName) + 2 /* slash + terminator */));
1213 if (!szFile)
1214 return E_OUTOFMEMORY;
1215
1216 lstrcpyW(szFile, szFilePath);
1217 lstrcatW(szFile, szSlashSep);
1218 lstrcatW(szFile, szFileName);
1219
1220 retval = GetFileVersionInfoSizeW(szFile, &hdl);
1221 if (retval)
1222 {
1223 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1224 if (!pVersionInfo)
1225 {
1226 hr = E_OUTOFMEMORY;
1227 goto cleanup;
1228 }
1229
1230 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1231 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1232 boolret = TRUE;
1233 }
1234
1235 hr = add_bstr_property(node, szPath, szFile);
1236 if (FAILED(hr))
1237 goto cleanup;
1238
1239 hr = add_bstr_property(node, szName, szFileName);
1240 if (FAILED(hr))
1241 goto cleanup;
1242
1243 hr = add_bool_property(node, bExists, boolret);
1244 if (FAILED(hr))
1245 goto cleanup;
1246
1247 if (boolret)
1248 {
1249 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
1250 szVersionFormat,
1251 HIWORD(pFileInfo->dwFileVersionMS),
1252 LOWORD(pFileInfo->dwFileVersionMS),
1253 HIWORD(pFileInfo->dwFileVersionLS),
1254 LOWORD(pFileInfo->dwFileVersionLS));
1255
1256 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1257
1258 hr = add_bstr_property(node, szVersion, szVersion_v);
1259 if (FAILED(hr))
1260 goto cleanup;
1261
1262 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1263 if (FAILED(hr))
1264 goto cleanup;
1265
1266 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1267 if (FAILED(hr))
1268 goto cleanup;
1269
1270 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1271 if (FAILED(hr))
1272 goto cleanup;
1273
1274 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1275 if (FAILED(hr))
1276 goto cleanup;
1277
1278 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1279 if (FAILED(hr))
1280 goto cleanup;
1281
1282 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1283 if (FAILED(hr))
1284 goto cleanup;
1285 }
1286
1287 hr = S_OK;
1288 cleanup:
1289 HeapFree(GetProcessHeap(), 0, pVersionInfo);
1290 HeapFree(GetProcessHeap(), 0, szFile);
1291
1292 return hr;
1293 }
1294 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1295 {
1296 static const WCHAR dlls[][15] =
1297 {
1298 {'d','3','d','8','.','d','l','l',0},
1299 {'d','3','d','9','.','d','l','l',0},
1300 {'d','d','r','a','w','.','d','l','l',0},
1301 {'d','e','v','e','n','u','m','.','d','l','l',0},
1302 {'d','i','n','p','u','t','8','.','d','l','l',0},
1303 {'d','i','n','p','u','t','.','d','l','l',0},
1304 {'d','m','b','a','n','d','.','d','l','l',0},
1305 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1306 {'d','m','i','m','e','.','d','l','l',0},
1307 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1308 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1309 {'d','m','s','t','y','l','e','.','d','l','l',0},
1310 {'d','m','s','y','n','t','h','.','d','l','l',0},
1311 {'d','m','u','s','i','c','.','d','l','l',0},
1312 {'d','p','l','a','y','x','.','d','l','l',0},
1313 {'d','p','n','e','t','.','d','l','l',0},
1314 {'d','s','o','u','n','d','.','d','l','l',0},
1315 {'d','s','w','a','v','e','.','d','l','l',0},
1316 {'d','x','d','i','a','g','n','.','d','l','l',0},
1317 {'q','u','a','r','t','z','.','d','l','l',0}
1318 };
1319
1320 HRESULT hr;
1321 WCHAR szFilePath[MAX_PATH];
1322 INT i;
1323
1324 GetSystemDirectoryW(szFilePath, MAX_PATH);
1325
1326 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
1327 {
1328 static const WCHAR szFormat[] = {'%','d',0};
1329
1330 WCHAR szFileID[5];
1331 IDxDiagContainerImpl_Container *file_container;
1332
1333 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
1334
1335 file_container = allocate_information_node(szFileID);
1336 if (!file_container)
1337 return E_OUTOFMEMORY;
1338
1339 hr = fill_file_description(file_container, szFilePath, dlls[i]);
1340 if (FAILED(hr))
1341 {
1342 free_information_tree(file_container);
1343 continue;
1344 }
1345
1346 add_subcontainer(node, file_container);
1347 }
1348
1349 return S_OK;
1350 }
1351
1352 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1353 {
1354 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1355 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1356
1357 HRESULT hr;
1358
1359 VariantInit(friendly_name);
1360 VariantInit(clsid_name);
1361
1362 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1363 if (FAILED(hr))
1364 return hr;
1365
1366 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1367 if (FAILED(hr))
1368 {
1369 VariantClear(friendly_name);
1370 return hr;
1371 }
1372
1373 return S_OK;
1374 }
1375
1376 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1377 {
1378 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1379 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1380 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1381 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1382 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1383
1384 HRESULT hr;
1385 IFilterMapper2 *pFileMapper = NULL;
1386 IAMFilterData *pFilterData = NULL;
1387 BYTE *ppRF = NULL;
1388 REGFILTER2 *pRF = NULL;
1389 WCHAR bufferW[10];
1390 ULONG j;
1391 DWORD dwNOutputs = 0;
1392 DWORD dwNInputs = 0;
1393
1394 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1395 (void **)&pFileMapper);
1396 if (FAILED(hr))
1397 return hr;
1398
1399 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1400 if (FAILED(hr))
1401 goto cleanup;
1402
1403 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&ppRF);
1404 if (FAILED(hr))
1405 goto cleanup;
1406 pRF = ((REGFILTER2**)ppRF)[0];
1407
1408 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1409 hr = add_bstr_property(subcont, szVersionW, bufferW);
1410 if (FAILED(hr))
1411 goto cleanup;
1412
1413 if (pRF->dwVersion == 1)
1414 {
1415 for (j = 0; j < pRF->u.s1.cPins; j++)
1416 if (pRF->u.s1.rgPins[j].bOutput)
1417 dwNOutputs++;
1418 else
1419 dwNInputs++;
1420 }
1421 else if (pRF->dwVersion == 2)
1422 {
1423 for (j = 0; j < pRF->u.s2.cPins2; j++)
1424 if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1425 dwNOutputs++;
1426 else
1427 dwNInputs++;
1428 }
1429
1430 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1431 if (FAILED(hr))
1432 goto cleanup;
1433
1434 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1435 if (FAILED(hr))
1436 goto cleanup;
1437
1438 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1439 if (FAILED(hr))
1440 goto cleanup;
1441
1442 hr = S_OK;
1443 cleanup:
1444 CoTaskMemFree(pRF);
1445 if (pFilterData) IAMFilterData_Release(pFilterData);
1446 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1447
1448 return hr;
1449 }
1450
1451 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1452 {
1453 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1454 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1455 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1456
1457 HRESULT hr;
1458 IPropertyBag *pPropFilterBag = NULL;
1459 BYTE *pData;
1460 VARIANT friendly_name;
1461 VARIANT clsid_name;
1462 VARIANT v;
1463
1464 VariantInit(&friendly_name);
1465 VariantInit(&clsid_name);
1466 VariantInit(&v);
1467
1468 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1469 if (FAILED(hr))
1470 return hr;
1471
1472 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1473 if (FAILED(hr))
1474 goto cleanup;
1475
1476 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1477 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1478
1479 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1480 if (FAILED(hr))
1481 goto cleanup;
1482
1483 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1484 if (FAILED(hr))
1485 goto cleanup;
1486
1487 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1488 if (FAILED(hr))
1489 goto cleanup;
1490
1491 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1492 if (FAILED(hr))
1493 goto cleanup;
1494
1495 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1496 SafeArrayUnaccessData(V_ARRAY(&v));
1497 if (FAILED(hr))
1498 goto cleanup;
1499
1500 hr = S_OK;
1501 cleanup:
1502 VariantClear(&v);
1503 VariantClear(&clsid_name);
1504 VariantClear(&friendly_name);
1505 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1506
1507 return hr;
1508 }
1509
1510 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1511 {
1512 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1513 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1514 static const WCHAR szIdFormat[] = {'%','d',0};
1515
1516 HRESULT hr;
1517 int i = 0;
1518 ICreateDevEnum *pCreateDevEnum;
1519 IEnumMoniker *pEmCat = NULL;
1520 IMoniker *pMCat = NULL;
1521 IEnumMoniker *pEnum = NULL;
1522
1523 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1524 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1525 if (FAILED(hr))
1526 return hr;
1527
1528 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1529 if (FAILED(hr))
1530 goto cleanup;
1531
1532 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1533 {
1534 VARIANT vCatName;
1535 VARIANT vCatClsid;
1536 IPropertyBag *pPropBag;
1537 CLSID clsidCat;
1538 IMoniker *pMoniker = NULL;
1539
1540 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1541 if (FAILED(hr))
1542 {
1543 IMoniker_Release(pMCat);
1544 break;
1545 }
1546
1547 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1548 IPropertyBag_Release(pPropBag);
1549 if (FAILED(hr))
1550 {
1551 IMoniker_Release(pMCat);
1552 break;
1553 }
1554
1555 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1556 if (FAILED(hr))
1557 {
1558 IMoniker_Release(pMCat);
1559 VariantClear(&vCatClsid);
1560 VariantClear(&vCatName);
1561 break;
1562 }
1563
1564 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1565 if (hr != S_OK)
1566 {
1567 IMoniker_Release(pMCat);
1568 VariantClear(&vCatClsid);
1569 VariantClear(&vCatName);
1570 continue;
1571 }
1572
1573 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1574
1575 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1576 {
1577 WCHAR bufferW[10];
1578 IDxDiagContainerImpl_Container *subcont;
1579
1580 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1581 subcont = allocate_information_node(bufferW);
1582 if (!subcont)
1583 {
1584 hr = E_OUTOFMEMORY;
1585 IMoniker_Release(pMoniker);
1586 break;
1587 }
1588
1589 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1590 if (FAILED(hr))
1591 {
1592 free_information_tree(subcont);
1593 IMoniker_Release(pMoniker);
1594 break;
1595 }
1596
1597 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1598 if (FAILED(hr))
1599 {
1600 free_information_tree(subcont);
1601 IMoniker_Release(pMoniker);
1602 break;
1603 }
1604
1605 hr = fill_filter_container(subcont, pMoniker);
1606 if (FAILED(hr))
1607 {
1608 free_information_tree(subcont);
1609 IMoniker_Release(pMoniker);
1610 break;
1611 }
1612
1613 add_subcontainer(node, subcont);
1614 i++;
1615 IMoniker_Release(pMoniker);
1616 }
1617
1618 IEnumMoniker_Release(pEnum);
1619 IMoniker_Release(pMCat);
1620 VariantClear(&vCatClsid);
1621 VariantClear(&vCatName);
1622
1623 if (FAILED(hr))
1624 break;
1625 }
1626
1627 cleanup:
1628 if (pEmCat) IEnumMoniker_Release(pEmCat);
1629 ICreateDevEnum_Release(pCreateDevEnum);
1630 return hr;
1631 }
1632
1633 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1634 {
1635 return S_OK;
1636 }
1637
1638 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1639 {
1640 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1641 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};
1642 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1643 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1644 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1645 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1646 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};
1647 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1648 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};
1649 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1650
1651 static const struct
1652 {
1653 const WCHAR *name;
1654 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1655 } root_children[] =
1656 {
1657 {DxDiag_SystemInfo, build_systeminfo_tree},
1658 {DxDiag_DisplayDevices, build_displaydevices_tree},
1659 {DxDiag_DirectSound, build_directsound_tree},
1660 {DxDiag_DirectMusic, build_directmusic_tree},
1661 {DxDiag_DirectInput, build_directinput_tree},
1662 {DxDiag_DirectPlay, build_directplay_tree},
1663 {DxDiag_SystemDevices, build_systemdevices_tree},
1664 {DxDiag_DirectXFiles, build_directxfiles_tree},
1665 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1666 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1667 };
1668
1669 IDxDiagContainerImpl_Container *info_root;
1670 size_t index;
1671
1672 info_root = allocate_information_node(NULL);
1673 if (!info_root)
1674 return E_OUTOFMEMORY;
1675
1676 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1677 {
1678 IDxDiagContainerImpl_Container *node;
1679 HRESULT hr;
1680
1681 node = allocate_information_node(root_children[index].name);
1682 if (!node)
1683 {
1684 free_information_tree(info_root);
1685 return E_OUTOFMEMORY;
1686 }
1687
1688 hr = root_children[index].initfunc(node);
1689 if (FAILED(hr))
1690 {
1691 free_information_tree(node);
1692 free_information_tree(info_root);
1693 return hr;
1694 }
1695
1696 add_subcontainer(info_root, node);
1697 }
1698
1699 *pinfo_root = info_root;
1700 return S_OK;
1701 }