msxml3: Remove no longer used get_xml() option to mess with encoding attribute.
[wine.git] / dlls / dxdiagn / provider.c
blob1e00a90bdff2d70662f0f6daeabff038587b2ee3
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
23 #include "config.h"
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "dxdiag_private.h"
29 #include "wine/unicode.h"
30 #include "winver.h"
31 #include "objidl.h"
32 #include "dshow.h"
33 #include "vfw.h"
34 #include "mmddk.h"
35 #include "ddraw.h"
36 #include "d3d9.h"
37 #include "strmif.h"
38 #include "initguid.h"
39 #include "fil_data.h"
40 #include "psapi.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
46 static const WCHAR szEmpty[] = {0};
48 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
49 static void free_information_tree(IDxDiagContainerImpl_Container *node);
51 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
52 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
53 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
54 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
55 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
56 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
57 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
58 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
59 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
60 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
61 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};
62 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};
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};
70 struct IDxDiagProviderImpl
72 IDxDiagProvider IDxDiagProvider_iface;
73 LONG ref;
74 BOOL init;
75 DXDIAG_INIT_PARAMS params;
76 IDxDiagContainerImpl_Container *info_root;
79 static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
81 return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
84 /* IDxDiagProvider IUnknown parts follow: */
85 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
86 void **ppobj)
88 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
90 if (!ppobj) return E_INVALIDARG;
92 if (IsEqualGUID(riid, &IID_IUnknown)
93 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
94 IUnknown_AddRef(iface);
95 *ppobj = This;
96 return S_OK;
99 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
100 *ppobj = NULL;
101 return E_NOINTERFACE;
104 static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
106 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
107 ULONG refCount = InterlockedIncrement(&This->ref);
109 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
111 DXDIAGN_LockModule();
113 return refCount;
116 static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
118 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
119 ULONG refCount = InterlockedDecrement(&This->ref);
121 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
123 if (!refCount) {
124 free_information_tree(This->info_root);
125 HeapFree(GetProcessHeap(), 0, This);
128 DXDIAGN_UnlockModule();
130 return refCount;
133 /* IDxDiagProvider Interface follow: */
134 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
135 DXDIAG_INIT_PARAMS *pParams)
137 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
138 HRESULT hr;
140 TRACE("(%p,%p)\n", iface, pParams);
142 if (NULL == pParams) {
143 return E_POINTER;
145 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
146 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
147 return E_INVALIDARG;
150 if (!This->info_root)
152 hr = build_information_tree(&This->info_root);
153 if (FAILED(hr))
154 return hr;
157 This->init = TRUE;
158 memcpy(&This->params, pParams, pParams->dwSize);
159 return S_OK;
162 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
163 IDxDiagContainer **ppInstance)
165 IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
167 TRACE("(%p,%p)\n", iface, ppInstance);
169 if (FALSE == This->init) {
170 return CO_E_NOTINITIALIZED;
173 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
174 &This->IDxDiagProvider_iface, (void **)ppInstance);
177 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
179 IDxDiagProviderImpl_QueryInterface,
180 IDxDiagProviderImpl_AddRef,
181 IDxDiagProviderImpl_Release,
182 IDxDiagProviderImpl_Initialize,
183 IDxDiagProviderImpl_GetRootContainer
186 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
187 IDxDiagProviderImpl* provider;
189 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
191 *ppobj = NULL;
192 if (punkOuter) return CLASS_E_NOAGGREGATION;
194 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
195 if (NULL == provider) return E_OUTOFMEMORY;
196 provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
197 provider->ref = 0; /* will be inited with QueryInterface */
198 return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
201 static void free_property_information(IDxDiagContainerImpl_Property *prop)
203 VariantClear(&prop->vProp);
204 HeapFree(GetProcessHeap(), 0, prop->propName);
205 HeapFree(GetProcessHeap(), 0, prop);
208 static void free_information_tree(IDxDiagContainerImpl_Container *node)
210 IDxDiagContainerImpl_Container *ptr, *cursor2;
212 if (!node)
213 return;
215 HeapFree(GetProcessHeap(), 0, node->contName);
217 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
219 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
221 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
223 list_remove(&prop->entry);
224 free_property_information(prop);
227 list_remove(&ptr->entry);
228 free_information_tree(ptr);
231 HeapFree(GetProcessHeap(), 0, node);
234 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
236 IDxDiagContainerImpl_Container *ret;
238 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
239 if (!ret)
240 return NULL;
242 if (name)
244 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
245 if (!ret->contName)
247 HeapFree(GetProcessHeap(), 0, ret);
248 return NULL;
250 strcpyW(ret->contName, name);
253 list_init(&ret->subContainers);
254 list_init(&ret->properties);
256 return ret;
259 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
261 IDxDiagContainerImpl_Property *ret;
263 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
264 if (!ret)
265 return NULL;
267 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
268 if (!ret->propName)
270 HeapFree(GetProcessHeap(), 0, ret);
271 return NULL;
273 strcpyW(ret->propName, name);
275 return ret;
278 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
280 list_add_tail(&node->subContainers, &subCont->entry);
281 ++node->nSubContainers;
284 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
286 IDxDiagContainerImpl_Property *prop;
287 BSTR bstr;
289 prop = allocate_property_information(propName);
290 if (!prop)
291 return E_OUTOFMEMORY;
293 bstr = SysAllocString(str);
294 if (!bstr)
296 free_property_information(prop);
297 return E_OUTOFMEMORY;
300 V_VT(&prop->vProp) = VT_BSTR;
301 V_BSTR(&prop->vProp) = bstr;
303 list_add_tail(&node->properties, &prop->entry);
304 ++node->nProperties;
306 return S_OK;
309 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
311 IDxDiagContainerImpl_Property *prop;
313 prop = allocate_property_information(propName);
314 if (!prop)
315 return E_OUTOFMEMORY;
317 V_VT(&prop->vProp) = VT_UI4;
318 V_UI4(&prop->vProp) = data;
320 list_add_tail(&node->properties, &prop->entry);
321 ++node->nProperties;
323 return S_OK;
326 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
328 IDxDiagContainerImpl_Property *prop;
330 prop = allocate_property_information(propName);
331 if (!prop)
332 return E_OUTOFMEMORY;
334 V_VT(&prop->vProp) = VT_BOOL;
335 V_BOOL(&prop->vProp) = data;
337 list_add_tail(&node->properties, &prop->entry);
338 ++node->nProperties;
340 return S_OK;
343 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
345 IDxDiagContainerImpl_Property *prop;
347 prop = allocate_property_information(propName);
348 if (!prop)
349 return E_OUTOFMEMORY;
351 V_VT(&prop->vProp) = VT_UI8;
352 V_UI8(&prop->vProp) = data;
354 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
356 list_add_tail(&node->properties, &prop->entry);
357 ++node->nProperties;
359 return S_OK;
362 /* Copied from programs/taskkill/taskkill.c. */
363 static DWORD *enumerate_processes(DWORD *list_count)
365 DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
367 pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
368 if (!pid_list)
369 return NULL;
371 for (;;)
373 DWORD *realloc_list;
375 if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
377 HeapFree(GetProcessHeap(), 0, pid_list);
378 return NULL;
381 /* EnumProcesses can't signal an insufficient buffer condition, so the
382 * only way to possibly determine whether a larger buffer is required
383 * is to see whether the written number of bytes is the same as the
384 * buffer size. If so, the buffer will be reallocated to twice the
385 * size. */
386 if (alloc_bytes != needed_bytes)
387 break;
389 alloc_bytes *= 2;
390 realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
391 if (!realloc_list)
393 HeapFree(GetProcessHeap(), 0, pid_list);
394 return NULL;
396 pid_list = realloc_list;
399 *list_count = needed_bytes / sizeof(*pid_list);
400 return pid_list;
403 /* Copied from programs/taskkill/taskkill.c. */
404 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
406 HANDLE process;
407 HMODULE module;
408 DWORD required_size;
410 process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
411 if (!process)
412 return FALSE;
414 if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
416 CloseHandle(process);
417 return FALSE;
420 if (!GetModuleBaseNameW(process, module, buf, chars))
422 CloseHandle(process);
423 return FALSE;
426 CloseHandle(process);
427 return TRUE;
430 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
431 static BOOL is_netmeeting_running(void)
433 static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
435 DWORD list_count;
436 DWORD *pid_list = enumerate_processes(&list_count);
438 if (pid_list)
440 DWORD i;
441 WCHAR process_name[MAX_PATH];
443 for (i = 0; i < list_count; i++)
445 if (get_process_name_from_pid(pid_list[i], process_name, sizeof(process_name)/sizeof(WCHAR)) &&
446 !lstrcmpW(conf_exe, process_name))
448 HeapFree(GetProcessHeap(), 0, pid_list);
449 return TRUE;
452 HeapFree(GetProcessHeap(), 0, pid_list);
455 return FALSE;
458 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
460 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
461 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
462 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};
463 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
465 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
466 HRESULT hr;
468 /* szLanguagesLocalized */
469 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
470 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
471 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
473 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
475 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
476 if (FAILED(hr))
477 return hr;
479 /* szLanguagesEnglish */
480 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
481 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
483 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
485 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
486 if (FAILED(hr))
487 return hr;
489 return S_OK;
492 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
494 static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
495 static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
496 static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
497 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
498 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
500 SYSTEMTIME curtime;
501 WCHAR date_str[80], time_str[80], datetime_str[200];
502 HRESULT hr;
504 GetLocalTime(&curtime);
506 GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, sizeof(time_str)/sizeof(WCHAR));
508 /* szTimeLocalized */
509 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, sizeof(date_str)/sizeof(WCHAR));
511 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
513 hr = add_bstr_property(node, szTimeLocalized, datetime_str);
514 if (FAILED(hr))
515 return hr;
517 /* szTimeEnglish */
518 GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, sizeof(date_str)/sizeof(WCHAR));
520 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
522 hr = add_bstr_property(node, szTimeEnglish, datetime_str);
523 if (FAILED(hr))
524 return hr;
526 return S_OK;
529 static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
531 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};
532 static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
533 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
534 static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
535 static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
536 static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
537 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
539 static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
540 szOSEnglish, szOSExEnglish, szOSExLongEnglish};
542 size_t i;
543 HRESULT hr;
545 /* FIXME: OS detection should be performed, and localized OS strings
546 * should contain translated versions of the "build" phrase. */
547 for (i = 0; i < sizeof(prop_list)/sizeof(prop_list[0]); i++)
549 hr = add_bstr_property(node, prop_list[i], winxpW);
550 if (FAILED(hr))
551 return hr;
554 return S_OK;
557 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
559 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};
560 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};
561 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};
562 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
563 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
564 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
565 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};
566 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
567 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};
568 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};
569 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
570 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
571 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
572 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
573 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
574 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
575 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
576 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
577 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
578 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
579 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};
580 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
581 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
582 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};
583 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};
584 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};
585 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};
586 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
587 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
588 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
589 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
591 static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
593 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};
594 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
596 HRESULT hr;
597 MEMORYSTATUSEX msex;
598 OSVERSIONINFOW info;
599 DWORD count, usedpage_mb, availpage_mb;
600 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
601 DWORD_PTR args[2];
603 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
604 if (FAILED(hr))
605 return hr;
607 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
608 if (FAILED(hr))
609 return hr;
611 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
612 if (FAILED(hr))
613 return hr;
615 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
616 if (FAILED(hr))
617 return hr;
619 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
620 if (FAILED(hr))
621 return hr;
623 hr = add_bool_property(node, bDebug, FALSE);
624 if (FAILED(hr))
625 return hr;
627 hr = add_bool_property(node, bNECPC98, FALSE);
628 if (FAILED(hr))
629 return hr;
631 msex.dwLength = sizeof(msex);
632 GlobalMemoryStatusEx(&msex);
634 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
635 if (FAILED(hr))
636 return hr;
638 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
639 if (FAILED(hr))
640 return hr;
642 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
643 if (FAILED(hr))
644 return hr;
646 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
647 if (FAILED(hr))
648 return hr;
650 info.dwOSVersionInfoSize = sizeof(info);
651 GetVersionExW(&info);
653 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
654 if (FAILED(hr))
655 return hr;
657 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
658 if (FAILED(hr))
659 return hr;
661 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
662 if (FAILED(hr))
663 return hr;
665 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
666 if (FAILED(hr))
667 return hr;
669 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
670 if (FAILED(hr))
671 return hr;
673 /* FIXME: Roundoff should not be done with truncated division. */
674 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
675 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
676 if (FAILED(hr))
677 return hr;
679 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
680 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
681 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
682 args[0] = usedpage_mb;
683 args[1] = availpage_mb;
684 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
685 localized_pagefile_fmt, 0, 0, print_buf,
686 sizeof(print_buf)/sizeof(*print_buf), (__ms_va_list*)args);
688 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
689 if (FAILED(hr))
690 return hr;
692 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
694 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
695 if (FAILED(hr))
696 return hr;
698 GetWindowsDirectoryW(buffer, MAX_PATH);
700 hr = add_bstr_property(node, szWindowsDir, buffer);
701 if (FAILED(hr))
702 return hr;
704 count = sizeof(computer_name)/sizeof(WCHAR);
705 if (!GetComputerNameW(computer_name, &count))
706 return E_FAIL;
708 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
709 if (FAILED(hr))
710 return hr;
712 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
713 if (FAILED(hr))
714 return hr;
716 hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
717 if (FAILED(hr))
718 return hr;
720 hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
721 if (FAILED(hr))
722 return hr;
724 hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
725 if (FAILED(hr))
726 return hr;
728 hr = add_bstr_property(node, szProcessorEnglish, szEmpty);
729 if (FAILED(hr))
730 return hr;
732 hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
733 if (FAILED(hr))
734 return hr;
736 hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
737 if (FAILED(hr))
738 return hr;
740 hr = fill_language_information(node);
741 if (FAILED(hr))
742 return hr;
744 hr = fill_datetime_information(node);
745 if (FAILED(hr))
746 return hr;
748 hr = fill_os_string_information(node, &info);
749 if (FAILED(hr))
750 return hr;
752 return S_OK;
755 /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
756 static DWORD depth_for_pixelformat(D3DFORMAT format)
758 switch (format)
760 case D3DFMT_P8: return 8;
761 case D3DFMT_X1R5G5B5: return 15;
762 case D3DFMT_R5G6B5: return 16;
763 /* This case will fail to distinguish an original bpp of 24. */
764 case D3DFMT_X8R8G8B8: return 32;
765 default:
766 FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
767 return 32;
771 static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
773 IDirectDraw7 *pDirectDraw;
774 HRESULT hr;
775 DDSCAPS2 dd_caps;
777 hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
778 if (SUCCEEDED(hr))
780 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
781 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
782 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
783 IDirectDraw7_Release(pDirectDraw);
784 if (SUCCEEDED(hr))
785 return TRUE;
788 return FALSE;
791 static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
793 static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
794 static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
795 static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
796 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
798 /* Enumeration copied from dlls/wined3d/wined3d_private.h and slightly modified. */
799 enum pci_vendor
801 HW_VENDOR_AMD = 0x1002,
802 HW_VENDOR_NVIDIA = 0x10de,
803 HW_VENDOR_INTEL = 0x8086,
806 switch (vendor_id)
808 case HW_VENDOR_AMD:
809 return atiW;
810 case HW_VENDOR_NVIDIA:
811 return nvidiaW;
812 case HW_VENDOR_INTEL:
813 return intelW;
814 default:
815 FIXME("Unknown PCI vendor ID 0x%04x\n", vendor_id);
816 return unknownW;
820 static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
822 IDxDiagContainerImpl_Container *display_adapter;
823 HRESULT hr;
824 IDirect3D9 *pDirect3D9;
825 WCHAR buffer[256];
826 UINT index, count;
828 pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
829 if (!pDirect3D9)
830 return E_FAIL;
832 count = IDirect3D9_GetAdapterCount(pDirect3D9);
833 for (index = 0; index < count; index++)
835 static const WCHAR adapterid_fmtW[] = {'%','u',0};
836 static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
837 static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
838 static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
839 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
841 D3DADAPTER_IDENTIFIER9 adapter_info;
842 D3DDISPLAYMODE adapter_mode;
843 DWORD available_mem = 0;
845 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), adapterid_fmtW, index);
846 display_adapter = allocate_information_node(buffer);
847 if (!display_adapter)
849 hr = E_OUTOFMEMORY;
850 goto cleanup;
853 add_subcontainer(node, display_adapter);
855 hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
856 if (SUCCEEDED(hr))
858 WCHAR driverW[sizeof(adapter_info.Driver)];
859 WCHAR descriptionW[sizeof(adapter_info.Description)];
860 WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
862 MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, sizeof(driverW)/sizeof(WCHAR));
863 MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW, sizeof(descriptionW)/sizeof(WCHAR));
864 MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW, sizeof(devicenameW)/sizeof(WCHAR));
866 hr = add_bstr_property(display_adapter, szDriverName, driverW);
867 if (FAILED(hr))
868 goto cleanup;
870 hr = add_bstr_property(display_adapter, szDescription, descriptionW);
871 if (FAILED(hr))
872 goto cleanup;
874 hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
875 if (FAILED(hr))
876 goto cleanup;
878 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), driverversion_fmtW,
879 HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
880 HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
882 hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
883 if (FAILED(hr))
884 goto cleanup;
886 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.VendorId);
887 hr = add_bstr_property(display_adapter, szVendorId, buffer);
888 if (FAILED(hr))
889 goto cleanup;
891 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.DeviceId);
892 hr = add_bstr_property(display_adapter, szDeviceId, buffer);
893 if (FAILED(hr))
894 goto cleanup;
896 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), subsysid_fmtW, adapter_info.SubSysId);
897 hr = add_bstr_property(display_adapter, szSubSysId, buffer);
898 if (FAILED(hr))
899 goto cleanup;
901 snprintfW(buffer, sizeof(buffer)/sizeof(WCHAR), id_fmtW, adapter_info.Revision);
902 hr = add_bstr_property(display_adapter, szRevisionId, buffer);
903 if (FAILED(hr))
904 goto cleanup;
906 StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
907 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
908 if (FAILED(hr))
909 goto cleanup;
911 hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
912 if (FAILED(hr))
913 goto cleanup;
916 hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
917 if (SUCCEEDED(hr))
919 hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
920 if (FAILED(hr))
921 goto cleanup;
923 hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
924 if (FAILED(hr))
925 goto cleanup;
927 hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
928 if (FAILED(hr))
929 goto cleanup;
931 hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
932 if (FAILED(hr))
933 goto cleanup;
936 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
937 if (FAILED(hr))
938 goto cleanup;
940 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
941 if (FAILED(hr))
942 goto cleanup;
944 if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
945 WARN("get_texture_memory helper failed\n");
947 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, available_mem / 1000000.0f);
949 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
950 if (FAILED(hr))
951 goto cleanup;
953 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
954 if (FAILED(hr))
955 goto cleanup;
958 hr = S_OK;
959 cleanup:
960 IDirect3D9_Release(pDirect3D9);
961 return hr;
964 static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
966 static const WCHAR szAdapterID[] = {'0',0};
967 static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
968 szKeyDeviceKey, szKeyDeviceID, szDriverName,
969 szDriverVersion, szSubSysId, szRevisionId,
970 szManufacturer};
972 IDxDiagContainerImpl_Container *display_adapter;
973 HRESULT hr;
974 IDirectDraw7 *pDirectDraw;
975 DDSCAPS2 dd_caps;
976 DISPLAY_DEVICEW disp_dev;
977 DDSURFACEDESC2 surface_descr;
978 DWORD tmp;
979 WCHAR buffer[256];
981 display_adapter = allocate_information_node(szAdapterID);
982 if (!display_adapter)
983 return E_OUTOFMEMORY;
985 add_subcontainer(node, display_adapter);
987 disp_dev.cb = sizeof(disp_dev);
988 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
990 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
991 if (FAILED(hr))
992 return hr;
994 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
995 if (FAILED(hr))
996 return hr;
999 /* Silently ignore a failure from DirectDrawCreateEx. */
1000 hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1001 if (FAILED(hr))
1002 return S_OK;
1004 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1005 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
1006 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1007 if (SUCCEEDED(hr))
1009 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1011 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, tmp / 1000000.0f);
1013 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1014 if (FAILED(hr))
1015 goto cleanup;
1017 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1018 if (FAILED(hr))
1019 goto cleanup;
1022 surface_descr.dwSize = sizeof(surface_descr);
1023 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1024 if (SUCCEEDED(hr))
1026 if (surface_descr.dwFlags & DDSD_WIDTH)
1028 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1029 if (FAILED(hr))
1030 goto cleanup;
1033 if (surface_descr.dwFlags & DDSD_HEIGHT)
1035 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1036 if (FAILED(hr))
1037 goto cleanup;
1040 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1042 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1043 if (FAILED(hr))
1044 goto cleanup;
1048 hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1049 if (FAILED(hr))
1050 goto cleanup;
1052 for (tmp = 0; tmp < sizeof(empty_properties)/sizeof(empty_properties[0]); tmp++)
1054 hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1055 if (FAILED(hr))
1056 goto cleanup;
1059 hr = S_OK;
1060 cleanup:
1061 IDirectDraw7_Release(pDirectDraw);
1062 return hr;
1065 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1067 HRESULT hr;
1069 /* Try to use Direct3D to obtain the required information first. */
1070 hr = fill_display_information_d3d(node);
1071 if (hr != E_FAIL)
1072 return hr;
1074 return fill_display_information_fallback(node);
1077 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1079 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1080 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};
1082 IDxDiagContainerImpl_Container *cont;
1084 cont = allocate_information_node(DxDiag_SoundDevices);
1085 if (!cont)
1086 return E_OUTOFMEMORY;
1088 add_subcontainer(node, cont);
1090 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1091 if (!cont)
1092 return E_OUTOFMEMORY;
1094 add_subcontainer(node, cont);
1096 return S_OK;
1099 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1101 return S_OK;
1104 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1106 return S_OK;
1109 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1111 return S_OK;
1114 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1116 return S_OK;
1119 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1121 static const WCHAR szSlashSep[] = {'\\',0};
1122 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1123 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1124 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1125 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1126 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1127 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1128 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1129 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1130 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1131 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1133 /* Values */
1134 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1135 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1136 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1138 HRESULT hr;
1139 WCHAR *szFile;
1140 WCHAR szVersion_v[1024];
1141 DWORD retval, hdl;
1142 void *pVersionInfo = NULL;
1143 BOOL boolret = FALSE;
1144 UINT uiLength;
1145 VS_FIXEDFILEINFO *pFileInfo;
1147 TRACE("Filling container %p for %s in %s\n", node,
1148 debugstr_w(szFileName), debugstr_w(szFilePath));
1150 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1151 lstrlenW(szFileName) + 2 /* slash + terminator */));
1152 if (!szFile)
1153 return E_OUTOFMEMORY;
1155 lstrcpyW(szFile, szFilePath);
1156 lstrcatW(szFile, szSlashSep);
1157 lstrcatW(szFile, szFileName);
1159 retval = GetFileVersionInfoSizeW(szFile, &hdl);
1160 if (retval)
1162 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1163 if (!pVersionInfo)
1165 hr = E_OUTOFMEMORY;
1166 goto cleanup;
1169 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1170 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1171 boolret = TRUE;
1174 hr = add_bstr_property(node, szPath, szFile);
1175 if (FAILED(hr))
1176 goto cleanup;
1178 hr = add_bstr_property(node, szName, szFileName);
1179 if (FAILED(hr))
1180 goto cleanup;
1182 hr = add_bool_property(node, bExists, boolret);
1183 if (FAILED(hr))
1184 goto cleanup;
1186 if (boolret)
1188 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
1189 szVersionFormat,
1190 HIWORD(pFileInfo->dwFileVersionMS),
1191 LOWORD(pFileInfo->dwFileVersionMS),
1192 HIWORD(pFileInfo->dwFileVersionLS),
1193 LOWORD(pFileInfo->dwFileVersionLS));
1195 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1197 hr = add_bstr_property(node, szVersion, szVersion_v);
1198 if (FAILED(hr))
1199 goto cleanup;
1201 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1202 if (FAILED(hr))
1203 goto cleanup;
1205 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1206 if (FAILED(hr))
1207 goto cleanup;
1209 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1210 if (FAILED(hr))
1211 goto cleanup;
1213 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1214 if (FAILED(hr))
1215 goto cleanup;
1217 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1218 if (FAILED(hr))
1219 goto cleanup;
1221 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1222 if (FAILED(hr))
1223 goto cleanup;
1226 hr = S_OK;
1227 cleanup:
1228 HeapFree(GetProcessHeap(), 0, pVersionInfo);
1229 HeapFree(GetProcessHeap(), 0, szFile);
1231 return hr;
1233 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1235 static const WCHAR dlls[][15] =
1237 {'d','3','d','8','.','d','l','l',0},
1238 {'d','3','d','9','.','d','l','l',0},
1239 {'d','d','r','a','w','.','d','l','l',0},
1240 {'d','e','v','e','n','u','m','.','d','l','l',0},
1241 {'d','i','n','p','u','t','8','.','d','l','l',0},
1242 {'d','i','n','p','u','t','.','d','l','l',0},
1243 {'d','m','b','a','n','d','.','d','l','l',0},
1244 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1245 {'d','m','i','m','e','.','d','l','l',0},
1246 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1247 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1248 {'d','m','s','t','y','l','e','.','d','l','l',0},
1249 {'d','m','s','y','n','t','h','.','d','l','l',0},
1250 {'d','m','u','s','i','c','.','d','l','l',0},
1251 {'d','p','l','a','y','x','.','d','l','l',0},
1252 {'d','p','n','e','t','.','d','l','l',0},
1253 {'d','s','o','u','n','d','.','d','l','l',0},
1254 {'d','s','w','a','v','e','.','d','l','l',0},
1255 {'d','x','d','i','a','g','n','.','d','l','l',0},
1256 {'q','u','a','r','t','z','.','d','l','l',0}
1259 HRESULT hr;
1260 WCHAR szFilePath[MAX_PATH];
1261 INT i;
1263 GetSystemDirectoryW(szFilePath, MAX_PATH);
1265 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
1267 static const WCHAR szFormat[] = {'%','d',0};
1269 WCHAR szFileID[5];
1270 IDxDiagContainerImpl_Container *file_container;
1272 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
1274 file_container = allocate_information_node(szFileID);
1275 if (!file_container)
1276 return E_OUTOFMEMORY;
1278 hr = fill_file_description(file_container, szFilePath, dlls[i]);
1279 if (FAILED(hr))
1281 free_information_tree(file_container);
1282 continue;
1285 add_subcontainer(node, file_container);
1288 return S_OK;
1291 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1293 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1294 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1296 HRESULT hr;
1298 VariantInit(friendly_name);
1299 VariantInit(clsid_name);
1301 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1302 if (FAILED(hr))
1303 return hr;
1305 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1306 if (FAILED(hr))
1308 VariantClear(friendly_name);
1309 return hr;
1312 return S_OK;
1315 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1317 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1318 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1319 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1320 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1321 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1323 HRESULT hr;
1324 IFilterMapper2 *pFileMapper = NULL;
1325 IAMFilterData *pFilterData = NULL;
1326 BYTE *ppRF = NULL;
1327 REGFILTER2 *pRF = NULL;
1328 WCHAR bufferW[10];
1329 ULONG j;
1330 DWORD dwNOutputs = 0;
1331 DWORD dwNInputs = 0;
1333 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1334 (void **)&pFileMapper);
1335 if (FAILED(hr))
1336 return hr;
1338 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1339 if (FAILED(hr))
1340 goto cleanup;
1342 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&ppRF);
1343 if (FAILED(hr))
1344 goto cleanup;
1345 pRF = ((REGFILTER2**)ppRF)[0];
1347 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1348 hr = add_bstr_property(subcont, szVersionW, bufferW);
1349 if (FAILED(hr))
1350 goto cleanup;
1352 if (pRF->dwVersion == 1)
1354 for (j = 0; j < pRF->u.s1.cPins; j++)
1355 if (pRF->u.s1.rgPins[j].bOutput)
1356 dwNOutputs++;
1357 else
1358 dwNInputs++;
1360 else if (pRF->dwVersion == 2)
1362 for (j = 0; j < pRF->u.s2.cPins2; j++)
1363 if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1364 dwNOutputs++;
1365 else
1366 dwNInputs++;
1369 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1370 if (FAILED(hr))
1371 goto cleanup;
1373 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1374 if (FAILED(hr))
1375 goto cleanup;
1377 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1378 if (FAILED(hr))
1379 goto cleanup;
1381 hr = S_OK;
1382 cleanup:
1383 CoTaskMemFree(pRF);
1384 if (pFilterData) IAMFilterData_Release(pFilterData);
1385 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1387 return hr;
1390 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1392 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1393 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1394 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1396 HRESULT hr;
1397 IPropertyBag *pPropFilterBag = NULL;
1398 BYTE *pData;
1399 VARIANT friendly_name;
1400 VARIANT clsid_name;
1401 VARIANT v;
1403 VariantInit(&friendly_name);
1404 VariantInit(&clsid_name);
1405 VariantInit(&v);
1407 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1408 if (FAILED(hr))
1409 return hr;
1411 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1412 if (FAILED(hr))
1413 goto cleanup;
1415 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1416 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1418 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1419 if (FAILED(hr))
1420 goto cleanup;
1422 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1423 if (FAILED(hr))
1424 goto cleanup;
1426 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1427 if (FAILED(hr))
1428 goto cleanup;
1430 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1431 if (FAILED(hr))
1432 goto cleanup;
1434 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1435 SafeArrayUnaccessData(V_ARRAY(&v));
1436 if (FAILED(hr))
1437 goto cleanup;
1439 hr = S_OK;
1440 cleanup:
1441 VariantClear(&v);
1442 VariantClear(&clsid_name);
1443 VariantClear(&friendly_name);
1444 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1446 return hr;
1449 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1451 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1452 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1453 static const WCHAR szIdFormat[] = {'%','d',0};
1455 HRESULT hr;
1456 int i = 0;
1457 ICreateDevEnum *pCreateDevEnum;
1458 IEnumMoniker *pEmCat = NULL;
1459 IMoniker *pMCat = NULL;
1460 IEnumMoniker *pEnum = NULL;
1462 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1463 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1464 if (FAILED(hr))
1465 return hr;
1467 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1468 if (FAILED(hr))
1469 goto cleanup;
1471 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1473 VARIANT vCatName;
1474 VARIANT vCatClsid;
1475 IPropertyBag *pPropBag;
1476 CLSID clsidCat;
1477 IMoniker *pMoniker = NULL;
1479 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1480 if (FAILED(hr))
1482 IMoniker_Release(pMCat);
1483 break;
1486 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1487 IPropertyBag_Release(pPropBag);
1488 if (FAILED(hr))
1490 IMoniker_Release(pMCat);
1491 break;
1494 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1495 if (FAILED(hr))
1497 IMoniker_Release(pMCat);
1498 VariantClear(&vCatClsid);
1499 VariantClear(&vCatName);
1500 break;
1503 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1504 if (hr != S_OK)
1506 IMoniker_Release(pMCat);
1507 VariantClear(&vCatClsid);
1508 VariantClear(&vCatName);
1509 continue;
1512 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1514 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1516 WCHAR bufferW[10];
1517 IDxDiagContainerImpl_Container *subcont;
1519 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1520 subcont = allocate_information_node(bufferW);
1521 if (!subcont)
1523 hr = E_OUTOFMEMORY;
1524 IMoniker_Release(pMoniker);
1525 break;
1528 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1529 if (FAILED(hr))
1531 free_information_tree(subcont);
1532 IMoniker_Release(pMoniker);
1533 break;
1536 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1537 if (FAILED(hr))
1539 free_information_tree(subcont);
1540 IMoniker_Release(pMoniker);
1541 break;
1544 hr = fill_filter_container(subcont, pMoniker);
1545 if (FAILED(hr))
1547 free_information_tree(subcont);
1548 IMoniker_Release(pMoniker);
1549 break;
1552 add_subcontainer(node, subcont);
1553 i++;
1554 IMoniker_Release(pMoniker);
1557 IEnumMoniker_Release(pEnum);
1558 IMoniker_Release(pMCat);
1559 VariantClear(&vCatClsid);
1560 VariantClear(&vCatName);
1562 if (FAILED(hr))
1563 break;
1566 cleanup:
1567 if (pEmCat) IEnumMoniker_Release(pEmCat);
1568 ICreateDevEnum_Release(pCreateDevEnum);
1569 return hr;
1572 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1574 return S_OK;
1577 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1579 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1580 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};
1581 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1582 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1583 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1584 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1585 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};
1586 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1587 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};
1588 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1590 static const struct
1592 const WCHAR *name;
1593 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1594 } root_children[] =
1596 {DxDiag_SystemInfo, build_systeminfo_tree},
1597 {DxDiag_DisplayDevices, build_displaydevices_tree},
1598 {DxDiag_DirectSound, build_directsound_tree},
1599 {DxDiag_DirectMusic, build_directmusic_tree},
1600 {DxDiag_DirectInput, build_directinput_tree},
1601 {DxDiag_DirectPlay, build_directplay_tree},
1602 {DxDiag_SystemDevices, build_systemdevices_tree},
1603 {DxDiag_DirectXFiles, build_directxfiles_tree},
1604 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1605 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1608 IDxDiagContainerImpl_Container *info_root;
1609 size_t index;
1611 info_root = allocate_information_node(NULL);
1612 if (!info_root)
1613 return E_OUTOFMEMORY;
1615 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1617 IDxDiagContainerImpl_Container *node;
1618 HRESULT hr;
1620 node = allocate_information_node(root_children[index].name);
1621 if (!node)
1623 free_information_tree(info_root);
1624 return E_OUTOFMEMORY;
1627 hr = root_children[index].initfunc(node);
1628 if (FAILED(hr))
1630 free_information_tree(node);
1631 free_information_tree(info_root);
1632 return hr;
1635 add_subcontainer(info_root, node);
1638 *pinfo_root = info_root;
1639 return S_OK;