dxdiagn: Add paged memory display string properties to the DxDiag_SystemInfo container.
[wine/multimedia.git] / dlls / dxdiagn / provider.c
blob1252272141fc6145854d03dda751c1d71e6adc3c
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 HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
47 static void free_information_tree(IDxDiagContainerImpl_Container *node);
49 /* IDxDiagProvider IUnknown parts follow: */
50 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
52 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
54 if (!ppobj) return E_INVALIDARG;
56 if (IsEqualGUID(riid, &IID_IUnknown)
57 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
58 IUnknown_AddRef(iface);
59 *ppobj = This;
60 return S_OK;
63 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
64 *ppobj = NULL;
65 return E_NOINTERFACE;
68 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
69 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
70 ULONG refCount = InterlockedIncrement(&This->ref);
72 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
74 DXDIAGN_LockModule();
76 return refCount;
79 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
80 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
81 ULONG refCount = InterlockedDecrement(&This->ref);
83 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
85 if (!refCount) {
86 free_information_tree(This->info_root);
87 HeapFree(GetProcessHeap(), 0, This);
90 DXDIAGN_UnlockModule();
92 return refCount;
95 /* IDxDiagProvider Interface follow: */
96 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
97 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
98 HRESULT hr;
100 TRACE("(%p,%p)\n", iface, pParams);
102 if (NULL == pParams) {
103 return E_POINTER;
105 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
106 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
107 return E_INVALIDARG;
110 if (!This->info_root)
112 hr = build_information_tree(&This->info_root);
113 if (FAILED(hr))
114 return hr;
117 This->init = TRUE;
118 memcpy(&This->params, pParams, pParams->dwSize);
119 return S_OK;
122 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
123 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
125 TRACE("(%p,%p)\n", iface, ppInstance);
127 if (FALSE == This->init) {
128 return CO_E_NOTINITIALIZED;
131 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
132 (IDxDiagProvider *)This, (void **)ppInstance);
135 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
137 IDxDiagProviderImpl_QueryInterface,
138 IDxDiagProviderImpl_AddRef,
139 IDxDiagProviderImpl_Release,
140 IDxDiagProviderImpl_Initialize,
141 IDxDiagProviderImpl_GetRootContainer
144 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
145 IDxDiagProviderImpl* provider;
147 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
149 *ppobj = NULL;
150 if (punkOuter) return CLASS_E_NOAGGREGATION;
152 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
153 if (NULL == provider) return E_OUTOFMEMORY;
154 provider->lpVtbl = &DxDiagProvider_Vtbl;
155 provider->ref = 0; /* will be inited with QueryInterface */
156 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
159 static void get_display_device_id(WCHAR *szIdentifierBuffer)
161 static const WCHAR szNA[] = {'n','/','a',0};
163 HRESULT hr = E_FAIL;
165 HMODULE d3d9_handle;
166 IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
167 IDirect3D9 *pD3d = NULL;
168 D3DADAPTER_IDENTIFIER9 adapter_ident;
170 /* Retrieves the display device identifier from the d3d9 implementation. */
171 d3d9_handle = LoadLibraryA("d3d9.dll");
172 if(d3d9_handle)
173 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
174 if(pDirect3DCreate9)
175 pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
176 if(pD3d)
177 hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
178 if(SUCCEEDED(hr)) {
179 StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
180 } else {
181 memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
184 if (pD3d)
185 IDirect3D9_Release(pD3d);
186 if (d3d9_handle)
187 FreeLibrary(d3d9_handle);
190 static void free_property_information(IDxDiagContainerImpl_Property *prop)
192 VariantClear(&prop->vProp);
193 HeapFree(GetProcessHeap(), 0, prop->propName);
194 HeapFree(GetProcessHeap(), 0, prop);
197 static void free_information_tree(IDxDiagContainerImpl_Container *node)
199 IDxDiagContainerImpl_Container *ptr, *cursor2;
201 if (!node)
202 return;
204 HeapFree(GetProcessHeap(), 0, node->contName);
206 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
208 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
210 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
212 list_remove(&prop->entry);
213 free_property_information(prop);
216 list_remove(&ptr->entry);
217 free_information_tree(ptr);
220 HeapFree(GetProcessHeap(), 0, node);
223 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
225 IDxDiagContainerImpl_Container *ret;
227 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
228 if (!ret)
229 return NULL;
231 if (name)
233 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
234 if (!ret->contName)
236 HeapFree(GetProcessHeap(), 0, ret);
237 return NULL;
239 strcpyW(ret->contName, name);
242 list_init(&ret->subContainers);
243 list_init(&ret->properties);
245 return ret;
248 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
250 IDxDiagContainerImpl_Property *ret;
252 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
253 if (!ret)
254 return NULL;
256 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
257 if (!ret->propName)
259 HeapFree(GetProcessHeap(), 0, ret);
260 return NULL;
262 strcpyW(ret->propName, name);
264 return ret;
267 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
269 list_add_tail(&node->subContainers, &subCont->entry);
270 ++node->nSubContainers;
273 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
275 IDxDiagContainerImpl_Property *prop;
276 BSTR bstr;
278 prop = allocate_property_information(propName);
279 if (!prop)
280 return E_OUTOFMEMORY;
282 bstr = SysAllocString(str);
283 if (!bstr)
285 free_property_information(prop);
286 return E_OUTOFMEMORY;
289 V_VT(&prop->vProp) = VT_BSTR;
290 V_BSTR(&prop->vProp) = bstr;
292 list_add_tail(&node->properties, &prop->entry);
293 ++node->nProperties;
295 return S_OK;
298 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
300 IDxDiagContainerImpl_Property *prop;
302 prop = allocate_property_information(propName);
303 if (!prop)
304 return E_OUTOFMEMORY;
306 V_VT(&prop->vProp) = VT_UI4;
307 V_UI4(&prop->vProp) = data;
309 list_add_tail(&node->properties, &prop->entry);
310 ++node->nProperties;
312 return S_OK;
315 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
317 IDxDiagContainerImpl_Property *prop;
319 prop = allocate_property_information(propName);
320 if (!prop)
321 return E_OUTOFMEMORY;
323 V_VT(&prop->vProp) = VT_BOOL;
324 V_BOOL(&prop->vProp) = data;
326 list_add_tail(&node->properties, &prop->entry);
327 ++node->nProperties;
329 return S_OK;
332 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
334 IDxDiagContainerImpl_Property *prop;
336 prop = allocate_property_information(propName);
337 if (!prop)
338 return E_OUTOFMEMORY;
340 V_VT(&prop->vProp) = VT_UI8;
341 V_UI8(&prop->vProp) = data;
343 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
345 list_add_tail(&node->properties, &prop->entry);
346 ++node->nProperties;
348 return S_OK;
351 /* Copied from programs/taskkill/taskkill.c. */
352 static DWORD *enumerate_processes(DWORD *list_count)
354 DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
356 pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
357 if (!pid_list)
358 return NULL;
360 for (;;)
362 DWORD *realloc_list;
364 if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
366 HeapFree(GetProcessHeap(), 0, pid_list);
367 return NULL;
370 /* EnumProcesses can't signal an insufficient buffer condition, so the
371 * only way to possibly determine whether a larger buffer is required
372 * is to see whether the written number of bytes is the same as the
373 * buffer size. If so, the buffer will be reallocated to twice the
374 * size. */
375 if (alloc_bytes != needed_bytes)
376 break;
378 alloc_bytes *= 2;
379 realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
380 if (!realloc_list)
382 HeapFree(GetProcessHeap(), 0, pid_list);
383 return NULL;
385 pid_list = realloc_list;
388 *list_count = needed_bytes / sizeof(*pid_list);
389 return pid_list;
392 /* Copied from programs/taskkill/taskkill.c. */
393 static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
395 HANDLE process;
396 HMODULE module;
397 DWORD required_size;
399 process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
400 if (!process)
401 return FALSE;
403 if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
405 CloseHandle(process);
406 return FALSE;
409 if (!GetModuleBaseNameW(process, module, buf, chars))
411 CloseHandle(process);
412 return FALSE;
415 CloseHandle(process);
416 return TRUE;
419 /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
420 static BOOL is_netmeeting_running(void)
422 static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
424 DWORD list_count;
425 DWORD *pid_list = enumerate_processes(&list_count);
427 if (pid_list)
429 DWORD i;
430 WCHAR process_name[MAX_PATH];
432 for (i = 0; i < list_count; i++)
434 if (get_process_name_from_pid(pid_list[i], process_name, sizeof(process_name)/sizeof(WCHAR)) &&
435 !lstrcmpW(conf_exe, process_name))
436 return TRUE;
440 return FALSE;
443 static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
445 static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
446 static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
447 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};
448 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
450 WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
451 HRESULT hr;
453 /* szLanguagesLocalized */
454 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, sizeof(system_lang)/sizeof(WCHAR));
455 LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, sizeof(regional_setting)/sizeof(WCHAR));
456 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, sizeof(user_lang)/sizeof(WCHAR));
458 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting, user_lang);
460 hr = add_bstr_property(node, szLanguagesLocalized, language_str);
461 if (FAILED(hr))
462 return hr;
464 /* szLanguagesEnglish */
465 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, sizeof(system_lang)/sizeof(WCHAR));
466 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, sizeof(user_lang)/sizeof(WCHAR));
468 snprintfW(language_str, sizeof(language_str)/sizeof(WCHAR), languages_fmtW, system_lang, regional_setting_engW, user_lang);
470 hr = add_bstr_property(node, szLanguagesEnglish, language_str);
471 if (FAILED(hr))
472 return hr;
474 return S_OK;
477 static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
479 static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
480 static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
481 static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
482 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
483 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
485 SYSTEMTIME curtime;
486 WCHAR date_str[80], time_str[80], datetime_str[200];
487 HRESULT hr;
489 GetLocalTime(&curtime);
491 GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, sizeof(time_str)/sizeof(WCHAR));
493 /* szTimeLocalized */
494 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, sizeof(date_str)/sizeof(WCHAR));
496 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
498 hr = add_bstr_property(node, szTimeLocalized, datetime_str);
499 if (FAILED(hr))
500 return hr;
502 /* szTimeEnglish */
503 GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, sizeof(date_str)/sizeof(WCHAR));
505 snprintfW(datetime_str, sizeof(datetime_str)/sizeof(WCHAR), datetime_fmtW, date_str, time_str);
507 hr = add_bstr_property(node, szTimeEnglish, datetime_str);
508 if (FAILED(hr))
509 return hr;
511 return S_OK;
514 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
516 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};
517 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};
518 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};
519 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
520 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
521 static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
522 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};
523 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
524 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};
525 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};
526 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
527 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
528 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
529 static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
530 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
531 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
532 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
533 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
534 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
535 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
536 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};
537 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
538 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
539 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};
540 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};
542 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};
543 static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
545 HRESULT hr;
546 MEMORYSTATUSEX msex;
547 OSVERSIONINFOW info;
548 DWORD count, usedpage_mb, availpage_mb;
549 WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
551 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
552 if (FAILED(hr))
553 return hr;
555 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
556 if (FAILED(hr))
557 return hr;
559 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
560 if (FAILED(hr))
561 return hr;
563 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
564 if (FAILED(hr))
565 return hr;
567 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
568 if (FAILED(hr))
569 return hr;
571 hr = add_bool_property(node, bDebug, FALSE);
572 if (FAILED(hr))
573 return hr;
575 hr = add_bool_property(node, bNECPC98, FALSE);
576 if (FAILED(hr))
577 return hr;
579 msex.dwLength = sizeof(msex);
580 GlobalMemoryStatusEx(&msex);
582 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
583 if (FAILED(hr))
584 return hr;
586 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
587 if (FAILED(hr))
588 return hr;
590 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
591 if (FAILED(hr))
592 return hr;
594 hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
595 if (FAILED(hr))
596 return hr;
598 info.dwOSVersionInfoSize = sizeof(info);
599 GetVersionExW(&info);
601 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
602 if (FAILED(hr))
603 return hr;
605 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
606 if (FAILED(hr))
607 return hr;
609 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
610 if (FAILED(hr))
611 return hr;
613 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
614 if (FAILED(hr))
615 return hr;
617 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
618 if (FAILED(hr))
619 return hr;
621 /* FIXME: Roundoff should not be done with truncated division. */
622 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), physmem_fmtW, (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
623 hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
624 if (FAILED(hr))
625 return hr;
627 usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
628 availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
629 LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt, sizeof(localized_pagefile_fmt)/sizeof(WCHAR));
630 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), localized_pagefile_fmt, usedpage_mb, availpage_mb);
632 hr = add_bstr_property(node, szPageFileLocalized, print_buf);
633 if (FAILED(hr))
634 return hr;
636 snprintfW(print_buf, sizeof(print_buf)/sizeof(WCHAR), pagefile_fmtW, usedpage_mb, availpage_mb);
638 hr = add_bstr_property(node, szPageFileEnglish, print_buf);
639 if (FAILED(hr))
640 return hr;
642 GetWindowsDirectoryW(buffer, MAX_PATH);
644 hr = add_bstr_property(node, szWindowsDir, buffer);
645 if (FAILED(hr))
646 return hr;
648 count = sizeof(computer_name)/sizeof(WCHAR);
649 if (!GetComputerNameW(computer_name, &count))
650 return E_FAIL;
652 hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
653 if (FAILED(hr))
654 return hr;
656 hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
657 if (FAILED(hr))
658 return hr;
660 hr = fill_language_information(node);
661 if (FAILED(hr))
662 return hr;
664 hr = fill_datetime_information(node);
665 if (FAILED(hr))
666 return hr;
668 return S_OK;
671 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
673 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
674 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
675 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
676 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
677 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
678 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
679 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
680 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
681 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
682 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
683 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};
684 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};
686 static const WCHAR szAdapterID[] = {'0',0};
687 static const WCHAR szEmpty[] = {0};
689 IDxDiagContainerImpl_Container *display_adapter;
690 HRESULT hr;
691 IDirectDraw7 *pDirectDraw;
692 DDSCAPS2 dd_caps;
693 DISPLAY_DEVICEW disp_dev;
694 DDSURFACEDESC2 surface_descr;
695 DWORD tmp;
696 WCHAR buffer[256];
698 display_adapter = allocate_information_node(szAdapterID);
699 if (!display_adapter)
700 return E_OUTOFMEMORY;
702 add_subcontainer(node, display_adapter);
704 disp_dev.cb = sizeof(disp_dev);
705 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
707 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
708 if (FAILED(hr))
709 return hr;
711 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
712 if (FAILED(hr))
713 return hr;
716 /* For now, silently ignore a failure from DirectDrawCreateEx. */
717 hr = DirectDrawCreateEx(NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
718 if (FAILED(hr))
719 return S_OK;
721 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
722 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
723 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
724 if (SUCCEEDED(hr))
726 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
728 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0);
730 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
731 if (FAILED(hr))
732 goto cleanup;
734 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
735 if (FAILED(hr))
736 goto cleanup;
739 surface_descr.dwSize = sizeof(surface_descr);
740 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
741 if (SUCCEEDED(hr))
743 if (surface_descr.dwFlags & DDSD_WIDTH)
745 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
746 if (FAILED(hr))
747 goto cleanup;
750 if (surface_descr.dwFlags & DDSD_HEIGHT)
752 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
753 if (FAILED(hr))
754 goto cleanup;
757 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
759 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
760 if (FAILED(hr))
761 goto cleanup;
765 get_display_device_id(buffer);
767 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
768 if (FAILED(hr))
769 goto cleanup;
771 hr = add_bstr_property(display_adapter, szVendorId, szEmpty);
772 if (FAILED(hr))
773 goto cleanup;
775 hr = add_bstr_property(display_adapter, szDeviceId, szEmpty);
776 if (FAILED(hr))
777 goto cleanup;
779 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
780 if (FAILED(hr))
781 goto cleanup;
783 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
784 if (FAILED(hr))
785 goto cleanup;
787 hr = S_OK;
788 cleanup:
789 IDirectDraw7_Release(pDirectDraw);
790 return hr;
793 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
795 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
796 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};
798 IDxDiagContainerImpl_Container *cont;
800 cont = allocate_information_node(DxDiag_SoundDevices);
801 if (!cont)
802 return E_OUTOFMEMORY;
804 add_subcontainer(node, cont);
806 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
807 if (!cont)
808 return E_OUTOFMEMORY;
810 add_subcontainer(node, cont);
812 return S_OK;
815 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
817 return S_OK;
820 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
822 return S_OK;
825 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
827 return S_OK;
830 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
832 return S_OK;
835 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
837 static const WCHAR szSlashSep[] = {'\\',0};
838 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
839 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
840 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
841 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
842 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
843 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
844 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
845 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
846 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
847 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
849 /* Values */
850 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
851 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
852 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
854 HRESULT hr;
855 WCHAR *szFile;
856 WCHAR szVersion_v[1024];
857 DWORD retval, hdl;
858 void *pVersionInfo = NULL;
859 BOOL boolret = FALSE;
860 UINT uiLength;
861 VS_FIXEDFILEINFO *pFileInfo;
863 TRACE("Filling container %p for %s in %s\n", node,
864 debugstr_w(szFileName), debugstr_w(szFilePath));
866 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
867 lstrlenW(szFileName) + 2 /* slash + terminator */));
868 if (!szFile)
869 return E_OUTOFMEMORY;
871 lstrcpyW(szFile, szFilePath);
872 lstrcatW(szFile, szSlashSep);
873 lstrcatW(szFile, szFileName);
875 retval = GetFileVersionInfoSizeW(szFile, &hdl);
876 if (retval)
878 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
879 if (!pVersionInfo)
881 hr = E_OUTOFMEMORY;
882 goto cleanup;
885 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
886 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
887 boolret = TRUE;
890 hr = add_bstr_property(node, szPath, szFile);
891 if (FAILED(hr))
892 goto cleanup;
894 hr = add_bstr_property(node, szName, szFileName);
895 if (FAILED(hr))
896 goto cleanup;
898 hr = add_bool_property(node, bExists, boolret);
899 if (FAILED(hr))
900 goto cleanup;
902 if (boolret)
904 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
905 szVersionFormat,
906 HIWORD(pFileInfo->dwFileVersionMS),
907 LOWORD(pFileInfo->dwFileVersionMS),
908 HIWORD(pFileInfo->dwFileVersionLS),
909 LOWORD(pFileInfo->dwFileVersionLS));
911 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
913 hr = add_bstr_property(node, szVersion, szVersion_v);
914 if (FAILED(hr))
915 goto cleanup;
917 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
918 if (FAILED(hr))
919 goto cleanup;
921 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
922 if (FAILED(hr))
923 goto cleanup;
925 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
926 if (FAILED(hr))
927 goto cleanup;
929 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
930 if (FAILED(hr))
931 goto cleanup;
933 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
934 if (FAILED(hr))
935 goto cleanup;
937 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
938 if (FAILED(hr))
939 goto cleanup;
942 hr = S_OK;
943 cleanup:
944 HeapFree(GetProcessHeap(), 0, pVersionInfo);
945 HeapFree(GetProcessHeap(), 0, szFile);
947 return hr;
949 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
951 static const WCHAR dlls[][15] =
953 {'d','3','d','8','.','d','l','l',0},
954 {'d','3','d','9','.','d','l','l',0},
955 {'d','d','r','a','w','.','d','l','l',0},
956 {'d','e','v','e','n','u','m','.','d','l','l',0},
957 {'d','i','n','p','u','t','8','.','d','l','l',0},
958 {'d','i','n','p','u','t','.','d','l','l',0},
959 {'d','m','b','a','n','d','.','d','l','l',0},
960 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
961 {'d','m','i','m','e','.','d','l','l',0},
962 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
963 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
964 {'d','m','s','t','y','l','e','.','d','l','l',0},
965 {'d','m','s','y','n','t','h','.','d','l','l',0},
966 {'d','m','u','s','i','c','.','d','l','l',0},
967 {'d','p','l','a','y','x','.','d','l','l',0},
968 {'d','p','n','e','t','.','d','l','l',0},
969 {'d','s','o','u','n','d','.','d','l','l',0},
970 {'d','s','w','a','v','e','.','d','l','l',0},
971 {'d','x','d','i','a','g','n','.','d','l','l',0},
972 {'q','u','a','r','t','z','.','d','l','l',0}
975 HRESULT hr;
976 WCHAR szFilePath[MAX_PATH];
977 INT i;
979 GetSystemDirectoryW(szFilePath, MAX_PATH);
981 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
983 static const WCHAR szFormat[] = {'%','d',0};
985 WCHAR szFileID[5];
986 IDxDiagContainerImpl_Container *file_container;
988 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
990 file_container = allocate_information_node(szFileID);
991 if (!file_container)
992 return E_OUTOFMEMORY;
994 hr = fill_file_description(file_container, szFilePath, dlls[i]);
995 if (FAILED(hr))
997 free_information_tree(file_container);
998 continue;
1001 add_subcontainer(node, file_container);
1004 return S_OK;
1007 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1009 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1010 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1012 HRESULT hr;
1014 VariantInit(friendly_name);
1015 VariantInit(clsid_name);
1017 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1018 if (FAILED(hr))
1019 return hr;
1021 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1022 if (FAILED(hr))
1024 VariantClear(friendly_name);
1025 return hr;
1028 return S_OK;
1031 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1033 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1034 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1035 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1036 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1037 static const WCHAR szVersionFormat[] = {'v','%','d',0};
1039 HRESULT hr;
1040 IFilterMapper2 *pFileMapper = NULL;
1041 IAMFilterData *pFilterData = NULL;
1042 REGFILTER2 *pRF = NULL;
1043 WCHAR bufferW[10];
1044 ULONG j;
1045 DWORD dwNOutputs = 0;
1046 DWORD dwNInputs = 0;
1048 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1049 (void **)&pFileMapper);
1050 if (FAILED(hr))
1051 return hr;
1053 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1054 if (FAILED(hr))
1055 goto cleanup;
1057 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&pRF);
1058 if (FAILED(hr))
1059 goto cleanup;
1061 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
1062 hr = add_bstr_property(subcont, szVersionW, bufferW);
1063 if (FAILED(hr))
1064 goto cleanup;
1066 if (pRF->dwVersion == 1)
1068 for (j = 0; j < pRF->u.s.cPins; j++)
1069 if (pRF->u.s.rgPins[j].bOutput)
1070 dwNOutputs++;
1071 else
1072 dwNInputs++;
1074 else if (pRF->dwVersion == 2)
1076 for (j = 0; j < pRF->u.s1.cPins2; j++)
1077 if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1078 dwNOutputs++;
1079 else
1080 dwNInputs++;
1083 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1084 if (FAILED(hr))
1085 goto cleanup;
1087 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1088 if (FAILED(hr))
1089 goto cleanup;
1091 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1092 if (FAILED(hr))
1093 goto cleanup;
1095 hr = S_OK;
1096 cleanup:
1097 CoTaskMemFree(pRF);
1098 if (pFilterData) IAMFilterData_Release(pFilterData);
1099 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1101 return hr;
1104 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1106 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1107 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1108 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1110 HRESULT hr;
1111 IPropertyBag *pPropFilterBag = NULL;
1112 BYTE *pData;
1113 VARIANT friendly_name;
1114 VARIANT clsid_name;
1115 VARIANT v;
1117 VariantInit(&friendly_name);
1118 VariantInit(&clsid_name);
1119 VariantInit(&v);
1121 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1122 if (FAILED(hr))
1123 return hr;
1125 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1126 if (FAILED(hr))
1127 goto cleanup;
1129 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1130 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1132 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1133 if (FAILED(hr))
1134 goto cleanup;
1136 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1137 if (FAILED(hr))
1138 goto cleanup;
1140 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1141 if (FAILED(hr))
1142 goto cleanup;
1144 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1145 if (FAILED(hr))
1146 goto cleanup;
1148 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1149 SafeArrayUnaccessData(V_ARRAY(&v));
1150 if (FAILED(hr))
1151 goto cleanup;
1153 hr = S_OK;
1154 cleanup:
1155 VariantClear(&v);
1156 VariantClear(&clsid_name);
1157 VariantClear(&friendly_name);
1158 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1160 return hr;
1163 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1165 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1166 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1167 static const WCHAR szIdFormat[] = {'%','d',0};
1169 HRESULT hr;
1170 int i = 0;
1171 ICreateDevEnum *pCreateDevEnum;
1172 IEnumMoniker *pEmCat = NULL;
1173 IMoniker *pMCat = NULL;
1174 IEnumMoniker *pEnum = NULL;
1176 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1177 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1178 if (FAILED(hr))
1179 return hr;
1181 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1182 if (FAILED(hr))
1183 goto cleanup;
1185 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1187 VARIANT vCatName;
1188 VARIANT vCatClsid;
1189 IPropertyBag *pPropBag;
1190 CLSID clsidCat;
1191 IMoniker *pMoniker = NULL;
1193 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1194 if (FAILED(hr))
1196 IMoniker_Release(pMCat);
1197 break;
1200 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1201 IPropertyBag_Release(pPropBag);
1202 if (FAILED(hr))
1204 IMoniker_Release(pMCat);
1205 break;
1208 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1209 if (FAILED(hr))
1211 IMoniker_Release(pMCat);
1212 VariantClear(&vCatClsid);
1213 VariantClear(&vCatName);
1214 break;
1217 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1218 if (hr != S_OK)
1220 IMoniker_Release(pMCat);
1221 VariantClear(&vCatClsid);
1222 VariantClear(&vCatName);
1223 continue;
1226 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1228 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1230 WCHAR bufferW[10];
1231 IDxDiagContainerImpl_Container *subcont;
1233 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1234 subcont = allocate_information_node(bufferW);
1235 if (!subcont)
1237 hr = E_OUTOFMEMORY;
1238 IMoniker_Release(pMoniker);
1239 break;
1242 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1243 if (FAILED(hr))
1245 free_information_tree(subcont);
1246 IMoniker_Release(pMoniker);
1247 break;
1250 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1251 if (FAILED(hr))
1253 free_information_tree(subcont);
1254 IMoniker_Release(pMoniker);
1255 break;
1258 hr = fill_filter_container(subcont, pMoniker);
1259 if (FAILED(hr))
1261 free_information_tree(subcont);
1262 IMoniker_Release(pMoniker);
1263 break;
1266 add_subcontainer(node, subcont);
1267 i++;
1268 IMoniker_Release(pMoniker);
1271 IEnumMoniker_Release(pEnum);
1272 IMoniker_Release(pMCat);
1273 VariantClear(&vCatClsid);
1274 VariantClear(&vCatName);
1276 if (FAILED(hr))
1277 break;
1280 cleanup:
1281 if (pEmCat) IEnumMoniker_Release(pEmCat);
1282 ICreateDevEnum_Release(pCreateDevEnum);
1283 return hr;
1286 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1288 return S_OK;
1291 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1293 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1294 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};
1295 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1296 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1297 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1298 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1299 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};
1300 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1301 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};
1302 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1304 static const struct
1306 const WCHAR *name;
1307 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1308 } root_children[] =
1310 {DxDiag_SystemInfo, build_systeminfo_tree},
1311 {DxDiag_DisplayDevices, build_displaydevices_tree},
1312 {DxDiag_DirectSound, build_directsound_tree},
1313 {DxDiag_DirectMusic, build_directmusic_tree},
1314 {DxDiag_DirectInput, build_directinput_tree},
1315 {DxDiag_DirectPlay, build_directplay_tree},
1316 {DxDiag_SystemDevices, build_systemdevices_tree},
1317 {DxDiag_DirectXFiles, build_directxfiles_tree},
1318 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1319 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1322 IDxDiagContainerImpl_Container *info_root;
1323 size_t index;
1325 info_root = allocate_information_node(NULL);
1326 if (!info_root)
1327 return E_OUTOFMEMORY;
1329 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1331 IDxDiagContainerImpl_Container *node;
1332 HRESULT hr;
1334 node = allocate_information_node(root_children[index].name);
1335 if (!node)
1337 free_information_tree(info_root);
1338 return E_OUTOFMEMORY;
1341 hr = root_children[index].initfunc(node);
1342 if (FAILED(hr))
1344 free_information_tree(node);
1345 free_information_tree(info_root);
1346 return hr;
1349 add_subcontainer(info_root, node);
1352 *pinfo_root = info_root;
1353 return S_OK;