dbghelp: Use local declarations of r_debug and link_map structs.
[wine.git] / dlls / dxdiagn / provider.c
blob6b6f4e640cc140398ac32af68d315adbb4e40733
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004-2005 Raphael Junqueira
5 * Copyright 2010 Andrew Nguyen
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.
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.
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
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "dxdiag_private.h"
28 #include "winver.h"
29 #include "objidl.h"
30 #include "uuids.h"
31 #include "vfw.h"
32 #include "mmddk.h"
33 #include "d3d9.h"
34 #include "strmif.h"
35 #include "initguid.h"
36 #include "wine/fil_data.h"
37 #include "psapi.h"
38 #include "wbemcli.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
44 static const WCHAR szEmpty[] = {0};
46 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
47 static void free_information_tree(IDxDiagContainerImpl_Container *node);
49 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
50 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
51 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
52 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
53 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
54 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
55 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
56 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
57 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
58 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
59 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};
60 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};
61 static const WCHAR szDisplayModeLocalized[] = {'s','z','D','i','s','p','l','a','y','M','o','d','e','L','o','c','a','l','i','z','e','d',0};
62 static const WCHAR szDisplayModeEnglish[] = {'s','z','D','i','s','p','l','a','y','M','o','d','e','E','n','g','l','i','s','h',0};
63 static const WCHAR szDriverName[] = {'s','z','D','r','i','v','e','r','N','a','m','e',0};
64 static const WCHAR szDriverVersion[] = {'s','z','D','r','i','v','e','r','V','e','r','s','i','o','n',0};
65 static const WCHAR szSubSysId[] = {'s','z','S','u','b','S','y','s','I','d',0};
66 static const WCHAR szRevisionId[] = {'s','z','R','e','v','i','s','i','o','n','I','d',0};
67 static const WCHAR dwRefreshRate[] = {'d','w','R','e','f','r','e','s','h','R','a','t','e',0};
68 static const WCHAR szManufacturer[] = {'s','z','M','a','n','u','f','a','c','t','u','r','e','r',0};
69 static const WCHAR szChipType[] = {'s','z','C','h','i','p','T','y','p','e',0};
70 static const WCHAR szDACType[] = {'s','z','D','A','C','T','y','p','e',0};
71 static const WCHAR szRevision[] = {'s','z','R','e','v','i','s','i','o','n',0};
72 static const WCHAR szMonitorName[] = {'s','z','M','o','n','i','t','o','r','N','a','m','e',0};
73 static const WCHAR szMonitorMaxRes[] = {'s','z','M','o','n','i','t','o','r','M','a','x','R','e','s',0};
74 static const WCHAR szDriverAttributes[] = {'s','z','D','r','i','v','e','r','A','t','t','r','i','b','u','t','e','s',0};
75 static const WCHAR szDriverLanguageEnglish[] = {'s','z','D','r','i','v','e','r','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
76 static const WCHAR szDriverLanguageLocalized[] = {'s','z','D','r','i','v','e','r','L','a','n','g','u','a','g','e','L','o','c','a','l','i','z','e','d',0};
77 static const WCHAR szDriverDateEnglish[] = {'s','z','D','r','i','v','e','r','D','a','t','e','E','n','g','l','i','s','h',0};
78 static const WCHAR szDriverDateLocalized[] = {'s','z','D','r','i','v','e','r','D','a','t','e','L','o','c','a','l','i','z','e','d',0};
79 static const WCHAR lDriverSize[] = {'l','D','r','i','v','e','r','S','i','z','e',0};
80 static const WCHAR szMiniVdd[] = {'s','z','M','i','n','i','V','d','d',0};
81 static const WCHAR szMiniVddDateLocalized[] = {'s','z','M','i','n','i','V','d','d','D','a','t','e','L','o','c','a','l','i','z','e','d',0};
82 static const WCHAR szMiniVddDateEnglish[] = {'s','z','M','i','n','i','V','d','d','D','a','t','e','E','n','g','l','i','s','h',0};
83 static const WCHAR lMiniVddSize[] = {'l','M','i','n','i','V','d','d','S','i','z','e',0};
84 static const WCHAR szVdd[] = {'s','z','V','d','d',0};
85 static const WCHAR bCanRenderWindow[] = {'b','C','a','n','R','e','n','d','e','r','W','i','n','d','o','w',0};
86 static const WCHAR bDriverBeta[] = {'b','D','r','i','v','e','r','B','e','t','a',0};
87 static const WCHAR bDriverDebug[] = {'b','D','r','i','v','e','r','D','e','b','u','g',0};
88 static const WCHAR bDriverSigned[] = {'b','D','r','i','v','e','r','S','i','g','n','e','d',0};
89 static const WCHAR bDriverSignedValid[] = {'b','D','r','i','v','e','r','S','i','g','n','e','d','V','a','l','i','d',0};
90 static const WCHAR szDriverSignDate[] = {'s','z','D','r','i','v','e','r','S','i','g','n','D','a','t','e',0};
91 static const WCHAR dwDDIVersion[] = {'d','w','D','D','I','V','e','r','s','i','o','n',0};
92 static const WCHAR szDDIVersionEnglish[] = {'s','z','D','D','I','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
93 static const WCHAR szDDIVersionLocalized[] = {'s','z','D','D','I','V','e','r','s','i','o','n','L','o','c','a','l','i','z','e','d',0};
94 static const WCHAR iAdapter[] = {'i','A','d','a','p','t','e','r',0};
95 static const WCHAR dwWHQLLevel[] = {'d','w','W','H','Q','L','L','e','v','e','l',0};
97 struct IDxDiagProviderImpl
99 IDxDiagProvider IDxDiagProvider_iface;
100 LONG ref;
101 BOOL init;
102 DXDIAG_INIT_PARAMS params;
103 IDxDiagContainerImpl_Container *info_root;
106 static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
108 return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
111 /* IDxDiagProvider IUnknown parts follow: */
112 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
113 void **ppobj)
115 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
117 if (!ppobj) return E_INVALIDARG;
119 if (IsEqualGUID(riid, &IID_IUnknown)
120 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
121 IUnknown_AddRef(iface);
122 *ppobj = This;
123 return S_OK;
126 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
127 *ppobj = NULL;
128 return E_NOINTERFACE;
131 static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
133 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
134 ULONG refCount = InterlockedIncrement(&This->ref);
136 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
138 DXDIAGN_LockModule();
140 return refCount;
143 static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
145 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
146 ULONG refCount = InterlockedDecrement(&This->ref);
148 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
150 if (!refCount) {
151 free_information_tree(This->info_root);
152 HeapFree(GetProcessHeap(), 0, This);
155 DXDIAGN_UnlockModule();
157 return refCount;
160 /* IDxDiagProvider Interface follow: */
161 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
162 DXDIAG_INIT_PARAMS *pParams)
164 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
165 HRESULT hr;
167 TRACE("(%p,%p)\n", iface, pParams);
169 if (NULL == pParams) {
170 return E_POINTER;
172 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
173 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
174 return E_INVALIDARG;
177 if (!This->info_root)
179 hr = build_information_tree(&This->info_root);
180 if (FAILED(hr))
181 return hr;
184 This->init = TRUE;
185 memcpy(&This->params, pParams, pParams->dwSize);
186 return S_OK;
189 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
190 IDxDiagContainer **ppInstance)
192 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
194 TRACE("(%p,%p)\n", iface, ppInstance);
196 if (FALSE == This->init) {
197 return CO_E_NOTINITIALIZED;
200 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
201 &This->IDxDiagProvider_iface, (void **)ppInstance);
204 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
206 IDxDiagProviderImpl_QueryInterface,
207 IDxDiagProviderImpl_AddRef,
208 IDxDiagProviderImpl_Release,
209 IDxDiagProviderImpl_Initialize,
210 IDxDiagProviderImpl_GetRootContainer
213 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
214 IDxDiagProviderImpl* provider;
216 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
218 *ppobj = NULL;
219 if (punkOuter) return CLASS_E_NOAGGREGATION;
221 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
222 if (NULL == provider) return E_OUTOFMEMORY;
223 provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
224 provider->ref = 0; /* will be inited with QueryInterface */
225 return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
228 static void free_property_information(IDxDiagContainerImpl_Property *prop)
230 VariantClear(&prop->vProp);
231 HeapFree(GetProcessHeap(), 0, prop->propName);
232 HeapFree(GetProcessHeap(), 0, prop);
235 static void free_information_tree(IDxDiagContainerImpl_Container *node)
237 IDxDiagContainerImpl_Container *ptr, *cursor2;
239 if (!node)
240 return;
242 HeapFree(GetProcessHeap(), 0, node->contName);
244 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
246 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
248 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
250 list_remove(&prop->entry);
251 free_property_information(prop);
254 list_remove(&ptr->entry);
255 free_information_tree(ptr);
258 HeapFree(GetProcessHeap(), 0, node);
261 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
263 IDxDiagContainerImpl_Container *ret;
265 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
266 if (!ret)
267 return NULL;
269 if (name)
271 ret->contName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(*name));
272 if (!ret->contName)
274 HeapFree(GetProcessHeap(), 0, ret);
275 return NULL;
277 lstrcpyW(ret->contName, name);
280 list_init(&ret->subContainers);
281 list_init(&ret->properties);
283 return ret;
286 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
288 IDxDiagContainerImpl_Property *ret;
290 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
291 if (!ret)
292 return NULL;
294 ret->propName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(*name));
295 if (!ret->propName)
297 HeapFree(GetProcessHeap(), 0, ret);
298 return NULL;
300 lstrcpyW(ret->propName, name);
302 return ret;
305 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
307 list_add_tail(&node->subContainers, &subCont->entry);
308 ++node->nSubContainers;
311 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
313 IDxDiagContainerImpl_Property *prop;
314 BSTR bstr;
316 prop = allocate_property_information(propName);
317 if (!prop)
318 return E_OUTOFMEMORY;
320 bstr = SysAllocString(str);
321 if (!bstr)
323 free_property_information(prop);
324 return E_OUTOFMEMORY;
327 V_VT(&prop->vProp) = VT_BSTR;
328 V_BSTR(&prop->vProp) = bstr;
330 list_add_tail(&node->properties, &prop->entry);
331 ++node->nProperties;
333 return S_OK;
336 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
338 IDxDiagContainerImpl_Property *prop;
340 prop = allocate_property_information(propName);
341 if (!prop)
342 return E_OUTOFMEMORY;
344 V_VT(&prop->vProp) = VT_UI4;
345 V_UI4(&prop->vProp) = data;
347 list_add_tail(&node->properties, &prop->entry);
348 ++node->nProperties;
350 return S_OK;
353 static inline HRESULT add_i4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, LONG data)
355 IDxDiagContainerImpl_Property *prop;
357 prop = allocate_property_information(propName);
358 if (!prop)
359 return E_OUTOFMEMORY;
361 V_VT(&prop->vProp) = VT_I4;
362 V_I4(&prop->vProp) = data;
364 list_add_tail(&node->properties, &prop->entry);
365 ++node->nProperties;
367 return S_OK;
370 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
372 IDxDiagContainerImpl_Property *prop;
374 prop = allocate_property_information(propName);
375 if (!prop)
376 return E_OUTOFMEMORY;
378 V_VT(&prop->vProp) = VT_BOOL;
379 V_BOOL(&prop->vProp) = data ? VARIANT_TRUE : VARIANT_FALSE;
381 list_add_tail(&node->properties, &prop->entry);
382 ++node->nProperties;
384 return S_OK;
387 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
389 IDxDiagContainerImpl_Property *prop;
390 HRESULT hr;
392 prop = allocate_property_information(propName);
393 if (!prop)
394 return E_OUTOFMEMORY;
396 V_VT(&prop->vProp) = VT_UI8;
397 V_UI8(&prop->vProp) = data;
399 hr = VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
400 if (FAILED(hr))
402 free_property_information(prop);
403 return hr;
406 list_add_tail(&node->properties, &prop->entry);
407 ++node->nProperties;
409 return S_OK;
412 /* Copied from programs/taskkill/taskkill.c. */
413 static DWORD *enumerate_processes(DWORD *list_count)
415 DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
417 pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
418 if (!pid_list)
419 return NULL;
421 for (;;)
423 DWORD *realloc_list;
425 if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
427 HeapFree(GetProcessHeap(), 0, pid_list);
428 return NULL;
431 /* EnumProcesses can't signal an insufficient buffer condition, so the
432 * only way to possibly determine whether a larger buffer is required
433 * is to see whether the written number of bytes is the same as the
434 * buffer size. If so, the buffer will be reallocated to twice the
435 * size. */
436 if (alloc_bytes != needed_bytes)
437 break;
439 alloc_bytes *= 2;
440 realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
441 if (!realloc_list)
443 HeapFree(GetProcessHeap(), 0, pid_list);
444 return NULL;
446 pid_list = realloc_list;
449 *list_count = needed_bytes / sizeof(*pid_list);
450 return pid_list;
453 /* Copied from programs/taskkill/taskkill.c. */
454 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
456 HANDLE process;
457 HMODULE module;
458 DWORD required_size;
460 process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
461 if (!process)
462 return FALSE;
464 if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
466 CloseHandle(process);
467 return FALSE;
470 if (!GetModuleBaseNameW(process, module, buf, chars))
472 CloseHandle(process);
473 return FALSE;
476 CloseHandle(process);
477 return TRUE;
480 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
481 static BOOL is_netmeeting_running(void)
483 static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
485 DWORD list_count;
486 DWORD *pid_list = enumerate_processes(&list_count);
488 if (pid_list)
490 DWORD i;
491 WCHAR process_name[MAX_PATH];
493 for (i = 0; i < list_count; i++)
495 if (get_process_name_from_pid(pid_list[i], process_name, ARRAY_SIZE(process_name)) &&
496 !lstrcmpW(conf_exe, process_name))
498 HeapFree(GetProcessHeap(), 0, pid_list);
499 return TRUE;
502 HeapFree(GetProcessHeap(), 0, pid_list);
505 return FALSE;
508 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
510 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
511 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
512 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};
513 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
515 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
516 HRESULT hr;
518 /* szLanguagesLocalized */
519 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, ARRAY_SIZE(system_lang));
520 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, ARRAY_SIZE(regional_setting));
521 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, ARRAY_SIZE(user_lang));
523 swprintf(language_str, ARRAY_SIZE(language_str), languages_fmtW, system_lang, regional_setting,
524 user_lang);
526 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
527 if (FAILED(hr))
528 return hr;
530 /* szLanguagesEnglish */
531 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, ARRAY_SIZE(system_lang));
532 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, ARRAY_SIZE(user_lang));
534 swprintf(language_str, ARRAY_SIZE(language_str), languages_fmtW, system_lang,
535 regional_setting_engW, user_lang);
537 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
538 if (FAILED(hr))
539 return hr;
541 return S_OK;
544 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
546 static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
547 static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
548 static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
549 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
550 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
552 SYSTEMTIME curtime;
553 WCHAR date_str[80], time_str[80], datetime_str[200];
554 HRESULT hr;
556 GetLocalTime(&curtime);
558 GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, ARRAY_SIZE(time_str));
560 /* szTimeLocalized */
561 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, ARRAY_SIZE(date_str));
563 swprintf(datetime_str, ARRAY_SIZE(datetime_str), datetime_fmtW, date_str, time_str);
565 hr = add_bstr_property(node, szTimeLocalized, datetime_str);
566 if (FAILED(hr))
567 return hr;
569 /* szTimeEnglish */
570 GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, ARRAY_SIZE(date_str));
572 swprintf(datetime_str, ARRAY_SIZE(datetime_str), datetime_fmtW, date_str, time_str);
574 hr = add_bstr_property(node, szTimeEnglish, datetime_str);
575 if (FAILED(hr))
576 return hr;
578 return S_OK;
581 static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
583 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};
584 static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
585 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
586 static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
587 static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
588 static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
589 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
591 static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
592 szOSEnglish, szOSExEnglish, szOSExLongEnglish};
594 size_t i;
595 HRESULT hr;
597 /* FIXME: OS detection should be performed, and localized OS strings
598 * should contain translated versions of the "build" phrase. */
599 for (i = 0; i < ARRAY_SIZE(prop_list); i++)
601 hr = add_bstr_property(node, prop_list[i], winxpW);
602 if (FAILED(hr))
603 return hr;
606 return S_OK;
609 static HRESULT fill_processor_information(IDxDiagContainerImpl_Container *node)
611 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
613 static const WCHAR cimv2W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
614 static const WCHAR proc_classW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
615 static const WCHAR nameW[] = {'N','a','m','e',0};
616 static const WCHAR max_clock_speedW[] = {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
617 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};
619 static const WCHAR processor_fmtW[] = {'%','s','(','%','d',' ','C','P','U','s',')',',',' ','~','%','d','M','H','z',0};
621 IWbemLocator *wbem_locator;
622 IWbemServices *wbem_service;
623 IWbemClassObject *wbem_class;
624 IEnumWbemClassObject *wbem_enum;
625 VARIANT cpu_name, cpu_no, clock_speed;
626 WCHAR print_buf[200];
627 BSTR bstr;
628 ULONG no;
629 HRESULT hr;
631 hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void**)&wbem_locator);
632 if(FAILED(hr))
633 return hr;
635 bstr = SysAllocString(cimv2W);
636 if(!bstr) {
637 IWbemLocator_Release(wbem_locator);
638 return E_OUTOFMEMORY;
640 hr = IWbemLocator_ConnectServer(wbem_locator, bstr, NULL, NULL, NULL, 0, NULL, NULL, &wbem_service);
641 IWbemLocator_Release(wbem_locator);
642 SysFreeString(bstr);
643 if(FAILED(hr))
644 return hr;
646 bstr = SysAllocString(proc_classW);
647 if(!bstr) {
648 IWbemServices_Release(wbem_service);
649 return E_OUTOFMEMORY;
651 hr = IWbemServices_CreateInstanceEnum(wbem_service, bstr, WBEM_FLAG_SYSTEM_ONLY, NULL, &wbem_enum);
652 IWbemServices_Release(wbem_service);
653 SysFreeString(bstr);
654 if(FAILED(hr))
655 return hr;
657 hr = IEnumWbemClassObject_Next(wbem_enum, 1000, 1, &wbem_class, &no);
658 IEnumWbemClassObject_Release(wbem_enum);
659 if(FAILED(hr))
660 return hr;
662 hr = IWbemClassObject_Get(wbem_class, cpu_noW, 0, &cpu_no, NULL, NULL);
663 if(FAILED(hr)) {
664 IWbemClassObject_Release(wbem_class);
665 return hr;
667 hr = IWbemClassObject_Get(wbem_class, max_clock_speedW, 0, &clock_speed, NULL, NULL);
668 if(FAILED(hr)) {
669 IWbemClassObject_Release(wbem_class);
670 return hr;
672 hr = IWbemClassObject_Get(wbem_class, nameW, 0, &cpu_name, NULL, NULL);
673 IWbemClassObject_Release(wbem_class);
674 if(FAILED(hr))
675 return hr;
677 swprintf(print_buf, ARRAY_SIZE(print_buf), processor_fmtW,
678 V_BSTR(&cpu_name), V_I4(&cpu_no), V_I4(&clock_speed));
679 VariantClear(&cpu_name);
680 VariantClear(&cpu_no);
681 VariantClear(&clock_speed);
683 return add_bstr_property(node, szProcessorEnglish, print_buf);
686 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
688 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};
689 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};
690 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};
691 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
692 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
693 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
694 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};
695 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
696 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};
697 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};
698 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
699 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
700 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
701 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
702 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
703 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
704 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
705 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
706 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
707 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
708 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};
709 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
710 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
711 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};
712 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};
713 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};
714 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};
715 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
716 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
717 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
719 static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
721 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};
722 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
724 HRESULT hr;
725 MEMORYSTATUSEX msex;
726 OSVERSIONINFOW info;
727 DWORD count, usedpage_mb, availpage_mb;
728 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
729 DWORD_PTR args[2];
731 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
732 if (FAILED(hr))
733 return hr;
735 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
736 if (FAILED(hr))
737 return hr;
739 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
740 if (FAILED(hr))
741 return hr;
743 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
744 if (FAILED(hr))
745 return hr;
747 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
748 if (FAILED(hr))
749 return hr;
751 hr = add_bool_property(node, bDebug, FALSE);
752 if (FAILED(hr))
753 return hr;
755 hr = add_bool_property(node, bNECPC98, FALSE);
756 if (FAILED(hr))
757 return hr;
759 msex.dwLength = sizeof(msex);
760 GlobalMemoryStatusEx(&msex);
762 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
763 if (FAILED(hr))
764 return hr;
766 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
767 if (FAILED(hr))
768 return hr;
770 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
771 if (FAILED(hr))
772 return hr;
774 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
775 if (FAILED(hr))
776 return hr;
778 info.dwOSVersionInfoSize = sizeof(info);
779 GetVersionExW(&info);
781 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
782 if (FAILED(hr))
783 return hr;
785 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
786 if (FAILED(hr))
787 return hr;
789 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
790 if (FAILED(hr))
791 return hr;
793 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
794 if (FAILED(hr))
795 return hr;
797 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
798 if (FAILED(hr))
799 return hr;
801 /* FIXME: Roundoff should not be done with truncated division. */
802 swprintf(print_buf, ARRAY_SIZE(print_buf), physmem_fmtW,
803 (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
804 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
805 if (FAILED(hr))
806 return hr;
808 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
809 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
810 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt,
811 ARRAY_SIZE(localized_pagefile_fmt));
812 args[0] = usedpage_mb;
813 args[1] = availpage_mb;
814 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, localized_pagefile_fmt,
815 0, 0, print_buf, ARRAY_SIZE(print_buf), (__ms_va_list*)args);
817 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
818 if (FAILED(hr))
819 return hr;
821 swprintf(print_buf, ARRAY_SIZE(print_buf), pagefile_fmtW, usedpage_mb, availpage_mb);
823 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
824 if (FAILED(hr))
825 return hr;
827 GetWindowsDirectoryW(buffer, MAX_PATH);
829 hr = add_bstr_property(node, szWindowsDir, buffer);
830 if (FAILED(hr))
831 return hr;
833 count = ARRAY_SIZE(computer_name);
834 if (!GetComputerNameW(computer_name, &count))
835 return E_FAIL;
837 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
838 if (FAILED(hr))
839 return hr;
841 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
842 if (FAILED(hr))
843 return hr;
845 hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
846 if (FAILED(hr))
847 return hr;
849 hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
850 if (FAILED(hr))
851 return hr;
853 hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
854 if (FAILED(hr))
855 return hr;
857 hr = fill_processor_information(node);
858 if (FAILED(hr))
859 return hr;
861 hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
862 if (FAILED(hr))
863 return hr;
865 hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
866 if (FAILED(hr))
867 return hr;
869 hr = fill_language_information(node);
870 if (FAILED(hr))
871 return hr;
873 hr = fill_datetime_information(node);
874 if (FAILED(hr))
875 return hr;
877 hr = fill_os_string_information(node, &info);
878 if (FAILED(hr))
879 return hr;
881 return S_OK;
884 /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
885 static DWORD depth_for_pixelformat(D3DFORMAT format)
887 switch (format)
889 case D3DFMT_P8: return 8;
890 case D3DFMT_X1R5G5B5: return 15;
891 case D3DFMT_R5G6B5: return 16;
892 /* This case will fail to distinguish an original bpp of 24. */
893 case D3DFMT_X8R8G8B8: return 32;
894 default:
895 FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
896 return 32;
900 static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
902 IDirectDraw7 *pDirectDraw;
903 HRESULT hr;
904 DDSCAPS2 dd_caps;
906 hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
907 if (SUCCEEDED(hr))
909 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
910 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
911 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
912 IDirectDraw7_Release(pDirectDraw);
913 if (SUCCEEDED(hr))
914 return TRUE;
917 return FALSE;
920 static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
922 unsigned int i;
924 static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
925 static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
926 static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
927 static const WCHAR vmwareW[] = {'V','M','w','a','r','e',0};
928 static const WCHAR redhatW[] = {'R','e','d',' ','H','a','t',0};
929 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
930 static const struct
932 DWORD id;
933 const WCHAR *name;
935 vendors[] =
937 {0x1002, atiW},
938 {0x10de, nvidiaW},
939 {0x15ad, vmwareW},
940 {0x1af4, redhatW},
941 {0x8086, intelW},
944 for (i = 0; i < ARRAY_SIZE(vendors); ++i)
946 if (vendors[i].id == vendor_id)
947 return vendors[i].name;
950 FIXME("Unknown PCI vendor ID 0x%04x.\n", vendor_id);
952 return unknownW;
955 static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
957 IDxDiagContainerImpl_Container *display_adapter;
958 HRESULT hr;
959 IDirect3D9 *pDirect3D9;
960 WCHAR buffer[256];
961 UINT index, count;
963 pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
964 if (!pDirect3D9)
965 return E_FAIL;
967 count = IDirect3D9_GetAdapterCount(pDirect3D9);
968 for (index = 0; index < count; index++)
970 static const WCHAR adapterid_fmtW[] = {'%','u',0};
971 static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
972 static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
973 static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
974 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
975 static const WCHAR b3DAccelerationExists[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','x','i','s','t','s',0};
976 static const WCHAR b3DAccelerationEnabled[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
977 static const WCHAR bDDAccelerationEnabled[] = {'b','D','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
978 static const WCHAR bNoHardware[] = {'b','N','o','H','a','r','d','w','a','r','e',0};
979 static const WCHAR mode_fmtW[] = {'%','d',' ','x',' ','%','d',' ','(','%','d',' ','b','i','t',')',' ','(','%','d','H','z',')',0};
980 static const WCHAR gernericPNPMonitorW[] = {'G','e','n','e','r','i','c',' ','P','n','P',' ','M','o','n','i','t','o','r',0};
981 static const WCHAR failedToGetParameterW[] = {'F','a','i','l','e','d',' ','t','o',' ','g','e','t',' ','p','a','r','a','m','e','t','e','r',0};
982 static const WCHAR driverAttributesW[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
983 static const WCHAR englishW[] = {'E','n','g','l','i','s','h',0};
984 static const WCHAR driverDateEnglishW[] = {'1','/','1','/','2','0','1','6',' ','1','0',':','0','0',':','0','0',0};
985 static const WCHAR driverDateLocalW[] = {'1','/','1','/','2','0','1','6',' ','1','0',':','0','0',':','0','0',' ','A','M',0};
986 static const WCHAR naW[] = {'n','/','a',0};
987 static const WCHAR ddi11W[] = {'1','1',0};
989 D3DADAPTER_IDENTIFIER9 adapter_info;
990 D3DDISPLAYMODE adapter_mode;
991 D3DCAPS9 device_caps;
992 DWORD available_mem = 0;
993 BOOL hardware_accel;
995 swprintf(buffer, ARRAY_SIZE(buffer), adapterid_fmtW, index);
996 display_adapter = allocate_information_node(buffer);
997 if (!display_adapter)
999 hr = E_OUTOFMEMORY;
1000 goto cleanup;
1003 add_subcontainer(node, display_adapter);
1005 hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
1006 if (SUCCEEDED(hr))
1008 WCHAR driverW[sizeof(adapter_info.Driver)];
1009 WCHAR descriptionW[sizeof(adapter_info.Description)];
1010 WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
1012 MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, ARRAY_SIZE(driverW));
1013 MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW,
1014 ARRAY_SIZE(descriptionW));
1015 MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW,
1016 ARRAY_SIZE(devicenameW));
1018 hr = add_bstr_property(display_adapter, szDriverName, driverW);
1019 if (FAILED(hr))
1020 goto cleanup;
1022 hr = add_bstr_property(display_adapter, szDescription, descriptionW);
1023 if (FAILED(hr))
1024 goto cleanup;
1026 hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
1027 if (FAILED(hr))
1028 goto cleanup;
1030 swprintf(buffer, ARRAY_SIZE(buffer), driverversion_fmtW,
1031 HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
1032 HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
1034 hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
1035 if (FAILED(hr))
1036 goto cleanup;
1038 swprintf(buffer, ARRAY_SIZE(buffer), id_fmtW, adapter_info.VendorId);
1039 hr = add_bstr_property(display_adapter, szVendorId, buffer);
1040 if (FAILED(hr))
1041 goto cleanup;
1043 swprintf(buffer, ARRAY_SIZE(buffer), id_fmtW, adapter_info.DeviceId);
1044 hr = add_bstr_property(display_adapter, szDeviceId, buffer);
1045 if (FAILED(hr))
1046 goto cleanup;
1048 swprintf(buffer, ARRAY_SIZE(buffer), subsysid_fmtW, adapter_info.SubSysId);
1049 hr = add_bstr_property(display_adapter, szSubSysId, buffer);
1050 if (FAILED(hr))
1051 goto cleanup;
1053 swprintf(buffer, ARRAY_SIZE(buffer), id_fmtW, adapter_info.Revision);
1054 hr = add_bstr_property(display_adapter, szRevisionId, buffer);
1055 if (FAILED(hr))
1056 goto cleanup;
1058 StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
1059 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
1060 if (FAILED(hr))
1061 goto cleanup;
1063 hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
1064 if (FAILED(hr))
1065 goto cleanup;
1068 hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
1069 if (SUCCEEDED(hr))
1071 hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
1072 if (FAILED(hr))
1073 goto cleanup;
1075 hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
1076 if (FAILED(hr))
1077 goto cleanup;
1079 hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
1080 if (FAILED(hr))
1081 goto cleanup;
1083 hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
1084 if (FAILED(hr))
1085 goto cleanup;
1087 swprintf(buffer, ARRAY_SIZE(buffer), mode_fmtW, adapter_mode.Width, adapter_mode.Height,
1088 depth_for_pixelformat(adapter_mode.Format), adapter_mode.RefreshRate);
1090 hr = add_bstr_property(display_adapter, szDisplayModeLocalized, buffer);
1091 if (FAILED(hr))
1092 goto cleanup;
1094 hr = add_bstr_property(display_adapter, szDisplayModeEnglish, buffer);
1095 if (FAILED(hr))
1096 goto cleanup;
1099 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
1100 if (FAILED(hr))
1101 goto cleanup;
1103 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
1104 if (FAILED(hr))
1105 goto cleanup;
1107 hr = add_bstr_property(display_adapter, szChipType, szEmpty);
1108 if (FAILED(hr))
1109 goto cleanup;
1111 hr = add_bstr_property(display_adapter, szDACType, szEmpty);
1112 if (FAILED(hr))
1113 goto cleanup;
1115 hr = add_bstr_property(display_adapter, szRevision, szEmpty);
1116 if (FAILED(hr))
1117 goto cleanup;
1119 if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
1120 WARN("get_texture_memory helper failed\n");
1122 swprintf(buffer, ARRAY_SIZE(buffer), mem_fmt, available_mem / 1000000.0f);
1124 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1125 if (FAILED(hr))
1126 goto cleanup;
1128 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1129 if (FAILED(hr))
1130 goto cleanup;
1132 hr = IDirect3D9_GetDeviceCaps(pDirect3D9, index, D3DDEVTYPE_HAL, &device_caps);
1133 hardware_accel = SUCCEEDED(hr);
1135 hr = add_bool_property(display_adapter, b3DAccelerationEnabled, hardware_accel);
1136 if (FAILED(hr))
1137 goto cleanup;
1139 hr = add_bool_property(display_adapter, b3DAccelerationExists, hardware_accel);
1140 if (FAILED(hr))
1141 goto cleanup;
1143 hr = add_bool_property(display_adapter, bDDAccelerationEnabled, hardware_accel);
1144 if (FAILED(hr))
1145 goto cleanup;
1147 hr = add_bool_property(display_adapter, bNoHardware, FALSE);
1148 if (FAILED(hr))
1149 goto cleanup;
1151 hr = add_bool_property(display_adapter, bCanRenderWindow, TRUE);
1152 if (FAILED(hr))
1153 goto cleanup;
1155 hr = add_bstr_property(display_adapter, szMonitorName, gernericPNPMonitorW);
1156 if (FAILED(hr))
1157 goto cleanup;
1159 hr = add_bstr_property(display_adapter, szMonitorMaxRes, failedToGetParameterW);
1160 if (FAILED(hr))
1161 goto cleanup;
1163 hr = add_bstr_property(display_adapter, szDriverAttributes, driverAttributesW);
1164 if (FAILED(hr))
1165 goto cleanup;
1167 hr = add_bstr_property(display_adapter, szDriverLanguageEnglish, englishW);
1168 if (FAILED(hr))
1169 goto cleanup;
1171 hr = add_bstr_property(display_adapter, szDriverLanguageLocalized, englishW);
1172 if (FAILED(hr))
1173 goto cleanup;
1175 hr = add_bstr_property(display_adapter, szDriverDateEnglish, driverDateEnglishW);
1176 if (FAILED(hr))
1177 goto cleanup;
1179 hr = add_bstr_property(display_adapter, szDriverDateLocalized, driverDateLocalW);
1180 if (FAILED(hr))
1181 goto cleanup;
1183 hr = add_i4_property(display_adapter, lDriverSize, 10 * 1024 * 1024);
1184 if (FAILED(hr))
1185 goto cleanup;
1187 hr = add_bstr_property(display_adapter, szMiniVdd, naW);
1188 if (FAILED(hr))
1189 goto cleanup;
1191 hr = add_bstr_property(display_adapter, szMiniVddDateLocalized, naW);
1192 if (FAILED(hr))
1193 goto cleanup;
1195 hr = add_bstr_property(display_adapter, szMiniVddDateEnglish, naW);
1196 if (FAILED(hr))
1197 goto cleanup;
1199 hr = add_i4_property(display_adapter, lMiniVddSize, 0);
1200 if (FAILED(hr))
1201 goto cleanup;
1203 hr = add_bstr_property(display_adapter, szVdd, naW);
1204 if (FAILED(hr))
1205 goto cleanup;
1207 hr = add_bool_property(display_adapter, bDriverBeta, FALSE);
1208 if (FAILED(hr))
1209 goto cleanup;
1211 hr = add_bool_property(display_adapter, bDriverDebug, FALSE);
1212 if (FAILED(hr))
1213 goto cleanup;
1215 hr = add_bool_property(display_adapter, bDriverSigned, TRUE);
1216 if (FAILED(hr))
1217 goto cleanup;
1219 hr = add_bool_property(display_adapter, bDriverSignedValid, TRUE);
1220 if (FAILED(hr))
1221 goto cleanup;
1223 hr = add_bstr_property(display_adapter, szDriverSignDate, naW);
1224 if (FAILED(hr))
1225 goto cleanup;
1227 hr = add_ui4_property(display_adapter, dwDDIVersion, 11);
1228 if (FAILED(hr))
1229 goto cleanup;
1231 hr = add_bstr_property(display_adapter, szDDIVersionEnglish, ddi11W);
1232 if (FAILED(hr))
1233 goto cleanup;
1235 hr = add_bstr_property(display_adapter, szDDIVersionLocalized, ddi11W);
1236 if (FAILED(hr))
1237 goto cleanup;
1239 hr = add_ui4_property(display_adapter, iAdapter, index);
1240 if (FAILED(hr))
1241 goto cleanup;
1243 hr = add_ui4_property(display_adapter, dwWHQLLevel, 0);
1244 if (FAILED(hr))
1245 goto cleanup;
1248 hr = S_OK;
1249 cleanup:
1250 IDirect3D9_Release(pDirect3D9);
1251 return hr;
1254 static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
1256 static const WCHAR szAdapterID[] = {'0',0};
1257 static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
1258 szKeyDeviceKey, szKeyDeviceID, szDriverName,
1259 szDriverVersion, szSubSysId, szRevisionId,
1260 szManufacturer, szChipType, szDACType, szRevision};
1262 IDxDiagContainerImpl_Container *display_adapter;
1263 HRESULT hr;
1264 IDirectDraw7 *pDirectDraw;
1265 DDSCAPS2 dd_caps;
1266 DISPLAY_DEVICEW disp_dev;
1267 DDSURFACEDESC2 surface_descr;
1268 DWORD tmp;
1269 WCHAR buffer[256];
1271 display_adapter = allocate_information_node(szAdapterID);
1272 if (!display_adapter)
1273 return E_OUTOFMEMORY;
1275 add_subcontainer(node, display_adapter);
1277 disp_dev.cb = sizeof(disp_dev);
1278 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
1280 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
1281 if (FAILED(hr))
1282 return hr;
1284 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
1285 if (FAILED(hr))
1286 return hr;
1289 /* Silently ignore a failure from DirectDrawCreateEx. */
1290 hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1291 if (FAILED(hr))
1292 return S_OK;
1294 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1295 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
1296 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1297 if (SUCCEEDED(hr))
1299 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1301 swprintf(buffer, ARRAY_SIZE(buffer), mem_fmt, tmp / 1000000.0f);
1303 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1304 if (FAILED(hr))
1305 goto cleanup;
1307 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1308 if (FAILED(hr))
1309 goto cleanup;
1312 surface_descr.dwSize = sizeof(surface_descr);
1313 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1314 if (SUCCEEDED(hr))
1316 if (surface_descr.dwFlags & DDSD_WIDTH)
1318 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1319 if (FAILED(hr))
1320 goto cleanup;
1323 if (surface_descr.dwFlags & DDSD_HEIGHT)
1325 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1326 if (FAILED(hr))
1327 goto cleanup;
1330 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1332 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1333 if (FAILED(hr))
1334 goto cleanup;
1338 hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1339 if (FAILED(hr))
1340 goto cleanup;
1342 for (tmp = 0; tmp < ARRAY_SIZE(empty_properties); tmp++)
1344 hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1345 if (FAILED(hr))
1346 goto cleanup;
1349 hr = S_OK;
1350 cleanup:
1351 IDirectDraw7_Release(pDirectDraw);
1352 return hr;
1355 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1357 HRESULT hr;
1359 /* Try to use Direct3D to obtain the required information first. */
1360 hr = fill_display_information_d3d(node);
1361 if (hr != E_FAIL)
1362 return hr;
1364 return fill_display_information_fallback(node);
1367 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1369 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1370 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};
1372 IDxDiagContainerImpl_Container *cont;
1374 cont = allocate_information_node(DxDiag_SoundDevices);
1375 if (!cont)
1376 return E_OUTOFMEMORY;
1378 add_subcontainer(node, cont);
1380 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1381 if (!cont)
1382 return E_OUTOFMEMORY;
1384 add_subcontainer(node, cont);
1386 return S_OK;
1389 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1391 return S_OK;
1394 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1396 return S_OK;
1399 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1401 return S_OK;
1404 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1406 return S_OK;
1409 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1411 static const WCHAR szSlashSep[] = {'\\',0};
1412 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1413 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1414 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1415 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1416 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1417 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1418 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1419 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1420 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1421 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1423 /* Values */
1424 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1425 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1426 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1428 HRESULT hr;
1429 WCHAR *szFile;
1430 WCHAR szVersion_v[1024];
1431 DWORD retval, hdl;
1432 void *pVersionInfo = NULL;
1433 BOOL boolret = FALSE;
1434 UINT uiLength;
1435 VS_FIXEDFILEINFO *pFileInfo;
1437 TRACE("Filling container %p for %s in %s\n", node,
1438 debugstr_w(szFileName), debugstr_w(szFilePath));
1440 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1441 lstrlenW(szFileName) + 2 /* slash + terminator */));
1442 if (!szFile)
1443 return E_OUTOFMEMORY;
1445 lstrcpyW(szFile, szFilePath);
1446 lstrcatW(szFile, szSlashSep);
1447 lstrcatW(szFile, szFileName);
1449 retval = GetFileVersionInfoSizeW(szFile, &hdl);
1450 if (retval)
1452 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1453 if (!pVersionInfo)
1455 hr = E_OUTOFMEMORY;
1456 goto cleanup;
1459 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1460 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1461 boolret = TRUE;
1464 hr = add_bstr_property(node, szPath, szFile);
1465 if (FAILED(hr))
1466 goto cleanup;
1468 hr = add_bstr_property(node, szName, szFileName);
1469 if (FAILED(hr))
1470 goto cleanup;
1472 hr = add_bool_property(node, bExists, boolret);
1473 if (FAILED(hr))
1474 goto cleanup;
1476 if (boolret)
1478 swprintf(szVersion_v, ARRAY_SIZE(szVersion_v), szVersionFormat,
1479 HIWORD(pFileInfo->dwFileVersionMS), LOWORD(pFileInfo->dwFileVersionMS),
1480 HIWORD(pFileInfo->dwFileVersionLS), LOWORD(pFileInfo->dwFileVersionLS));
1482 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1484 hr = add_bstr_property(node, szVersion, szVersion_v);
1485 if (FAILED(hr))
1486 goto cleanup;
1488 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1489 if (FAILED(hr))
1490 goto cleanup;
1492 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1493 if (FAILED(hr))
1494 goto cleanup;
1496 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1497 if (FAILED(hr))
1498 goto cleanup;
1500 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1501 if (FAILED(hr))
1502 goto cleanup;
1504 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1505 if (FAILED(hr))
1506 goto cleanup;
1508 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1509 if (FAILED(hr))
1510 goto cleanup;
1513 hr = S_OK;
1514 cleanup:
1515 HeapFree(GetProcessHeap(), 0, pVersionInfo);
1516 HeapFree(GetProcessHeap(), 0, szFile);
1518 return hr;
1520 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1522 static const WCHAR dlls[][15] =
1524 {'d','3','d','8','.','d','l','l',0},
1525 {'d','3','d','9','.','d','l','l',0},
1526 {'d','d','r','a','w','.','d','l','l',0},
1527 {'d','e','v','e','n','u','m','.','d','l','l',0},
1528 {'d','i','n','p','u','t','8','.','d','l','l',0},
1529 {'d','i','n','p','u','t','.','d','l','l',0},
1530 {'d','m','b','a','n','d','.','d','l','l',0},
1531 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1532 {'d','m','i','m','e','.','d','l','l',0},
1533 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1534 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1535 {'d','m','s','t','y','l','e','.','d','l','l',0},
1536 {'d','m','s','y','n','t','h','.','d','l','l',0},
1537 {'d','m','u','s','i','c','.','d','l','l',0},
1538 {'d','p','l','a','y','x','.','d','l','l',0},
1539 {'d','p','n','e','t','.','d','l','l',0},
1540 {'d','s','o','u','n','d','.','d','l','l',0},
1541 {'d','s','w','a','v','e','.','d','l','l',0},
1542 {'d','x','d','i','a','g','n','.','d','l','l',0},
1543 {'q','u','a','r','t','z','.','d','l','l',0}
1546 HRESULT hr;
1547 WCHAR szFilePath[MAX_PATH];
1548 INT i;
1550 GetSystemDirectoryW(szFilePath, MAX_PATH);
1552 for (i = 0; i < ARRAY_SIZE(dlls); i++)
1554 static const WCHAR szFormat[] = {'%','d',0};
1556 WCHAR szFileID[5];
1557 IDxDiagContainerImpl_Container *file_container;
1559 swprintf(szFileID, ARRAY_SIZE(szFileID), szFormat, i);
1561 file_container = allocate_information_node(szFileID);
1562 if (!file_container)
1563 return E_OUTOFMEMORY;
1565 hr = fill_file_description(file_container, szFilePath, dlls[i]);
1566 if (FAILED(hr))
1568 free_information_tree(file_container);
1569 continue;
1572 add_subcontainer(node, file_container);
1575 return S_OK;
1578 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1580 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1581 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1583 HRESULT hr;
1585 VariantInit(friendly_name);
1586 VariantInit(clsid_name);
1588 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1589 if (FAILED(hr))
1590 return hr;
1592 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1593 if (FAILED(hr))
1595 VariantClear(friendly_name);
1596 return hr;
1599 return S_OK;
1602 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1604 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1605 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1606 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1607 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1608 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1610 HRESULT hr;
1611 IFilterMapper2 *pFileMapper = NULL;
1612 IAMFilterData *pFilterData = NULL;
1613 BYTE *ppRF = NULL;
1614 REGFILTER2 *pRF = NULL;
1615 WCHAR bufferW[10];
1616 ULONG j;
1617 DWORD dwNOutputs = 0;
1618 DWORD dwNInputs = 0;
1620 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1621 (void **)&pFileMapper);
1622 if (FAILED(hr))
1623 return hr;
1625 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1626 if (FAILED(hr))
1627 goto cleanup;
1629 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, &ppRF);
1630 if (FAILED(hr))
1631 goto cleanup;
1632 pRF = ((REGFILTER2**)ppRF)[0];
1634 swprintf(bufferW, ARRAY_SIZE(bufferW), szVersionFormat, pRF->dwVersion);
1635 hr = add_bstr_property(subcont, szVersionW, bufferW);
1636 if (FAILED(hr))
1637 goto cleanup;
1639 if (pRF->dwVersion == 1)
1641 for (j = 0; j < pRF->u.s1.cPins; j++)
1642 if (pRF->u.s1.rgPins[j].bOutput)
1643 dwNOutputs++;
1644 else
1645 dwNInputs++;
1647 else if (pRF->dwVersion == 2)
1649 for (j = 0; j < pRF->u.s2.cPins2; j++)
1650 if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1651 dwNOutputs++;
1652 else
1653 dwNInputs++;
1656 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1657 if (FAILED(hr))
1658 goto cleanup;
1660 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1661 if (FAILED(hr))
1662 goto cleanup;
1664 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1665 if (FAILED(hr))
1666 goto cleanup;
1668 hr = S_OK;
1669 cleanup:
1670 CoTaskMemFree(pRF);
1671 if (pFilterData) IAMFilterData_Release(pFilterData);
1672 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1674 return hr;
1677 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1679 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1680 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1681 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1683 HRESULT hr;
1684 IPropertyBag *pPropFilterBag = NULL;
1685 BYTE *pData;
1686 VARIANT friendly_name;
1687 VARIANT clsid_name;
1688 VARIANT v;
1690 VariantInit(&friendly_name);
1691 VariantInit(&clsid_name);
1692 VariantInit(&v);
1694 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1695 if (FAILED(hr))
1696 return hr;
1698 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1699 if (FAILED(hr))
1700 goto cleanup;
1702 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1703 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1705 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1706 if (FAILED(hr))
1707 goto cleanup;
1709 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1710 if (FAILED(hr))
1711 goto cleanup;
1713 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1714 if (FAILED(hr))
1715 goto cleanup;
1717 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1718 if (FAILED(hr))
1719 goto cleanup;
1721 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1722 SafeArrayUnaccessData(V_ARRAY(&v));
1723 if (FAILED(hr))
1724 goto cleanup;
1726 hr = S_OK;
1727 cleanup:
1728 VariantClear(&v);
1729 VariantClear(&clsid_name);
1730 VariantClear(&friendly_name);
1731 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1733 return hr;
1736 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1738 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1739 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1740 static const WCHAR szIdFormat[] = {'%','d',0};
1742 HRESULT hr;
1743 int i = 0;
1744 ICreateDevEnum *pCreateDevEnum;
1745 IEnumMoniker *pEmCat = NULL;
1746 IMoniker *pMCat = NULL;
1747 IEnumMoniker *pEnum = NULL;
1749 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1750 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1751 if (FAILED(hr))
1752 return hr;
1754 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1755 if (FAILED(hr))
1756 goto cleanup;
1758 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1760 VARIANT vCatName;
1761 VARIANT vCatClsid;
1762 IPropertyBag *pPropBag;
1763 CLSID clsidCat;
1764 IMoniker *pMoniker = NULL;
1766 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1767 if (FAILED(hr))
1769 IMoniker_Release(pMCat);
1770 break;
1773 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1774 IPropertyBag_Release(pPropBag);
1775 if (FAILED(hr))
1777 IMoniker_Release(pMCat);
1778 break;
1781 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1782 if (FAILED(hr))
1784 IMoniker_Release(pMCat);
1785 VariantClear(&vCatClsid);
1786 VariantClear(&vCatName);
1787 break;
1790 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1791 if (hr != S_OK)
1793 IMoniker_Release(pMCat);
1794 VariantClear(&vCatClsid);
1795 VariantClear(&vCatName);
1796 continue;
1799 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1801 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1803 WCHAR bufferW[10];
1804 IDxDiagContainerImpl_Container *subcont;
1806 swprintf(bufferW, ARRAY_SIZE(bufferW), szIdFormat, i);
1807 subcont = allocate_information_node(bufferW);
1808 if (!subcont)
1810 hr = E_OUTOFMEMORY;
1811 IMoniker_Release(pMoniker);
1812 break;
1815 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1816 if (FAILED(hr))
1818 free_information_tree(subcont);
1819 IMoniker_Release(pMoniker);
1820 break;
1823 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1824 if (FAILED(hr))
1826 free_information_tree(subcont);
1827 IMoniker_Release(pMoniker);
1828 break;
1831 hr = fill_filter_container(subcont, pMoniker);
1832 IMoniker_Release(pMoniker);
1833 if (FAILED(hr))
1835 WARN("Skipping invalid filter\n");
1836 free_information_tree(subcont);
1837 hr = S_OK;
1838 continue;
1841 add_subcontainer(node, subcont);
1842 i++;
1845 IEnumMoniker_Release(pEnum);
1846 IMoniker_Release(pMCat);
1847 VariantClear(&vCatClsid);
1848 VariantClear(&vCatName);
1850 if (FAILED(hr))
1851 break;
1854 cleanup:
1855 if (pEmCat) IEnumMoniker_Release(pEmCat);
1856 ICreateDevEnum_Release(pCreateDevEnum);
1857 return hr;
1860 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1862 return S_OK;
1865 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1867 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1868 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};
1869 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1870 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1871 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1872 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1873 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};
1874 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1875 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};
1876 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1878 static const struct
1880 const WCHAR *name;
1881 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1882 } root_children[] =
1884 {DxDiag_SystemInfo, build_systeminfo_tree},
1885 {DxDiag_DisplayDevices, build_displaydevices_tree},
1886 {DxDiag_DirectSound, build_directsound_tree},
1887 {DxDiag_DirectMusic, build_directmusic_tree},
1888 {DxDiag_DirectInput, build_directinput_tree},
1889 {DxDiag_DirectPlay, build_directplay_tree},
1890 {DxDiag_SystemDevices, build_systemdevices_tree},
1891 {DxDiag_DirectXFiles, build_directxfiles_tree},
1892 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1893 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1896 IDxDiagContainerImpl_Container *info_root;
1897 size_t index;
1899 info_root = allocate_information_node(NULL);
1900 if (!info_root)
1901 return E_OUTOFMEMORY;
1903 for (index = 0; index < ARRAY_SIZE(root_children); index++)
1905 IDxDiagContainerImpl_Container *node;
1906 HRESULT hr;
1908 node = allocate_information_node(root_children[index].name);
1909 if (!node)
1911 free_information_tree(info_root);
1912 return E_OUTOFMEMORY;
1915 hr = root_children[index].initfunc(node);
1916 if (FAILED(hr))
1918 free_information_tree(node);
1919 free_information_tree(info_root);
1920 return hr;
1923 add_subcontainer(info_root, node);
1926 *pinfo_root = info_root;
1927 return S_OK;