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