2 * IDxDiagProvider Implementation
4 * Copyright 2004-2005 Raphael Junqueira
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "dxdiag_private.h"
28 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
44 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
45 static void free_information_tree(IDxDiagContainerImpl_Container *node);
47 /* IDxDiagProvider IUnknown parts follow: */
48 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
50 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
52 if (!ppobj) return E_INVALIDARG;
54 if (IsEqualGUID(riid, &IID_IUnknown)
55 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
56 IUnknown_AddRef(iface);
61 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
66 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
67 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
68 ULONG refCount = InterlockedIncrement(&This->ref);
70 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
77 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
78 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
79 ULONG refCount = InterlockedDecrement(&This->ref);
81 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
84 free_information_tree(This->info_root);
85 HeapFree(GetProcessHeap(), 0, This);
88 DXDIAGN_UnlockModule();
93 /* IDxDiagProvider Interface follow: */
94 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
95 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
98 TRACE("(%p,%p)\n", iface, pParams);
100 if (NULL == pParams) {
103 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
104 pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
108 if (!This->info_root)
110 hr = build_information_tree(&This->info_root);
116 memcpy(&This->params, pParams, pParams->dwSize);
120 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
121 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
123 TRACE("(%p,%p)\n", iface, ppInstance);
125 if (FALSE == This->init) {
126 return CO_E_NOTINITIALIZED;
129 return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
130 (IDxDiagProvider *)This, (void **)ppInstance);
133 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
135 IDxDiagProviderImpl_QueryInterface,
136 IDxDiagProviderImpl_AddRef,
137 IDxDiagProviderImpl_Release,
138 IDxDiagProviderImpl_Initialize,
139 IDxDiagProviderImpl_GetRootContainer
142 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
143 IDxDiagProviderImpl* provider;
145 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
148 if (punkOuter) return CLASS_E_NOAGGREGATION;
150 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
151 if (NULL == provider) return E_OUTOFMEMORY;
152 provider->lpVtbl = &DxDiagProvider_Vtbl;
153 provider->ref = 0; /* will be inited with QueryInterface */
154 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
157 static void get_display_device_id(WCHAR *szIdentifierBuffer)
159 static const WCHAR szNA[] = {'n','/','a',0};
164 IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT) = NULL;
165 IDirect3D9 *pD3d = NULL;
166 D3DADAPTER_IDENTIFIER9 adapter_ident;
168 /* Retrieves the display device identifier from the d3d9 implementation. */
169 d3d9_handle = LoadLibraryA("d3d9.dll");
171 pDirect3DCreate9 = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
173 pD3d = pDirect3DCreate9(D3D_SDK_VERSION);
175 hr = IDirect3D9_GetAdapterIdentifier(pD3d, D3DADAPTER_DEFAULT, 0, &adapter_ident);
177 StringFromGUID2(&adapter_ident.DeviceIdentifier, szIdentifierBuffer, 39);
179 memcpy(szIdentifierBuffer, szNA, sizeof(szNA));
183 IDirect3D9_Release(pD3d);
185 FreeLibrary(d3d9_handle);
188 static void free_property_information(IDxDiagContainerImpl_Property *prop)
190 VariantClear(&prop->vProp);
191 HeapFree(GetProcessHeap(), 0, prop->propName);
192 HeapFree(GetProcessHeap(), 0, prop);
195 static void free_information_tree(IDxDiagContainerImpl_Container *node)
197 IDxDiagContainerImpl_Container *ptr, *cursor2;
202 HeapFree(GetProcessHeap(), 0, node->contName);
204 LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
206 IDxDiagContainerImpl_Property *prop, *prop_cursor2;
208 LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
210 list_remove(&prop->entry);
211 free_property_information(prop);
214 list_remove(&ptr->entry);
215 free_information_tree(ptr);
218 HeapFree(GetProcessHeap(), 0, node);
221 static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
223 IDxDiagContainerImpl_Container *ret;
225 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
231 ret->contName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
234 HeapFree(GetProcessHeap(), 0, ret);
237 strcpyW(ret->contName, name);
240 list_init(&ret->subContainers);
241 list_init(&ret->properties);
246 static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
248 IDxDiagContainerImpl_Property *ret;
250 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
254 ret->propName = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(*name));
257 HeapFree(GetProcessHeap(), 0, ret);
260 strcpyW(ret->propName, name);
265 static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
267 list_add_tail(&node->subContainers, &subCont->entry);
268 ++node->nSubContainers;
271 static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
273 IDxDiagContainerImpl_Property *prop;
276 prop = allocate_property_information(propName);
278 return E_OUTOFMEMORY;
280 bstr = SysAllocString(str);
283 free_property_information(prop);
284 return E_OUTOFMEMORY;
287 V_VT(&prop->vProp) = VT_BSTR;
288 V_BSTR(&prop->vProp) = bstr;
290 list_add_tail(&node->properties, &prop->entry);
296 static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
298 IDxDiagContainerImpl_Property *prop;
300 prop = allocate_property_information(propName);
302 return E_OUTOFMEMORY;
304 V_VT(&prop->vProp) = VT_UI4;
305 V_UI4(&prop->vProp) = data;
307 list_add_tail(&node->properties, &prop->entry);
313 static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
315 IDxDiagContainerImpl_Property *prop;
317 prop = allocate_property_information(propName);
319 return E_OUTOFMEMORY;
321 V_VT(&prop->vProp) = VT_BOOL;
322 V_BOOL(&prop->vProp) = data;
324 list_add_tail(&node->properties, &prop->entry);
330 static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
332 IDxDiagContainerImpl_Property *prop;
334 prop = allocate_property_information(propName);
336 return E_OUTOFMEMORY;
338 V_VT(&prop->vProp) = VT_UI8;
339 V_UI8(&prop->vProp) = data;
341 VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
343 list_add_tail(&node->properties, &prop->entry);
349 static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
351 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};
352 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};
353 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};
354 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
355 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
356 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};
357 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
358 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};
359 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};
360 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
361 static const WCHAR ullUsedPageFile[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
362 static const WCHAR ullAvailPageFile[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
363 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
364 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
365 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
366 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
367 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
368 static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
373 WCHAR buffer[MAX_PATH];
375 hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
379 hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
383 hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
387 hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
391 hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
395 hr = add_bool_property(node, bDebug, FALSE);
399 msex.dwLength = sizeof(msex);
400 GlobalMemoryStatusEx(&msex);
402 hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
406 hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
410 hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
414 info.dwOSVersionInfoSize = sizeof(info);
415 GetVersionExW(&info);
417 hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
421 hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
425 hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
429 hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
433 hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
437 GetWindowsDirectoryW(buffer, MAX_PATH);
439 hr = add_bstr_property(node, szWindowsDir, buffer);
446 static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
448 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
449 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
450 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
451 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
452 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
453 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
454 static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
455 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
456 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
457 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
458 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};
459 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};
461 static const WCHAR szAdapterID[] = {'0',0};
462 static const WCHAR szEmpty[] = {0};
464 IDxDiagContainerImpl_Container *display_adapter;
466 IDirectDraw7 *pDirectDraw;
468 DISPLAY_DEVICEW disp_dev;
469 DDSURFACEDESC2 surface_descr;
473 display_adapter = allocate_information_node(szAdapterID);
474 if (!display_adapter)
475 return E_OUTOFMEMORY;
477 add_subcontainer(node, display_adapter);
479 disp_dev.cb = sizeof(disp_dev);
480 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
482 hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
486 hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
491 /* For now, silently ignore a failure from DirectDrawCreateEx. */
492 hr = DirectDrawCreateEx(NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
496 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
497 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
498 hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
501 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
503 snprintfW(buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0);
505 hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
509 hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
514 surface_descr.dwSize = sizeof(surface_descr);
515 hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
518 if (surface_descr.dwFlags & DDSD_WIDTH)
520 hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
525 if (surface_descr.dwFlags & DDSD_HEIGHT)
527 hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
532 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
534 hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
540 get_display_device_id(buffer);
542 hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
546 hr = add_bstr_property(display_adapter, szVendorId, szEmpty);
550 hr = add_bstr_property(display_adapter, szDeviceId, szEmpty);
554 hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
558 hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
564 IDirectDraw7_Release(pDirectDraw);
568 static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
570 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
571 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};
573 IDxDiagContainerImpl_Container *cont;
575 cont = allocate_information_node(DxDiag_SoundDevices);
577 return E_OUTOFMEMORY;
579 add_subcontainer(node, cont);
581 cont = allocate_information_node(DxDiag_SoundCaptureDevices);
583 return E_OUTOFMEMORY;
585 add_subcontainer(node, cont);
590 static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
595 static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
600 static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
605 static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
610 static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
612 static const WCHAR szSlashSep[] = {'\\',0};
613 static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
614 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
615 static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
616 static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
617 static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
618 static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
619 static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
620 static const WCHAR bBeta[] = {'b','B','e','t','a',0};
621 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
622 static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
625 static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
626 static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
627 static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
631 WCHAR szVersion_v[1024];
633 void *pVersionInfo = NULL;
634 BOOL boolret = FALSE;
636 VS_FIXEDFILEINFO *pFileInfo;
638 TRACE("Filling container %p for %s in %s\n", node,
639 debugstr_w(szFileName), debugstr_w(szFilePath));
641 szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
642 lstrlenW(szFileName) + 2 /* slash + terminator */));
644 return E_OUTOFMEMORY;
646 lstrcpyW(szFile, szFilePath);
647 lstrcatW(szFile, szSlashSep);
648 lstrcatW(szFile, szFileName);
650 retval = GetFileVersionInfoSizeW(szFile, &hdl);
653 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
660 if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
661 VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
665 hr = add_bstr_property(node, szPath, szFile);
669 hr = add_bstr_property(node, szName, szFileName);
673 hr = add_bool_property(node, bExists, boolret);
679 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
681 HIWORD(pFileInfo->dwFileVersionMS),
682 LOWORD(pFileInfo->dwFileVersionMS),
683 HIWORD(pFileInfo->dwFileVersionLS),
684 LOWORD(pFileInfo->dwFileVersionLS));
686 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
688 hr = add_bstr_property(node, szVersion, szVersion_v);
692 hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
696 hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
700 hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
704 hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
708 hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
712 hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
719 HeapFree(GetProcessHeap(), 0, pVersionInfo);
720 HeapFree(GetProcessHeap(), 0, szFile);
724 static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
726 static const WCHAR dlls[][15] =
728 {'d','3','d','8','.','d','l','l',0},
729 {'d','3','d','9','.','d','l','l',0},
730 {'d','d','r','a','w','.','d','l','l',0},
731 {'d','e','v','e','n','u','m','.','d','l','l',0},
732 {'d','i','n','p','u','t','8','.','d','l','l',0},
733 {'d','i','n','p','u','t','.','d','l','l',0},
734 {'d','m','b','a','n','d','.','d','l','l',0},
735 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
736 {'d','m','i','m','e','.','d','l','l',0},
737 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
738 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
739 {'d','m','s','t','y','l','e','.','d','l','l',0},
740 {'d','m','s','y','n','t','h','.','d','l','l',0},
741 {'d','m','u','s','i','c','.','d','l','l',0},
742 {'d','p','l','a','y','x','.','d','l','l',0},
743 {'d','p','n','e','t','.','d','l','l',0},
744 {'d','s','o','u','n','d','.','d','l','l',0},
745 {'d','s','w','a','v','e','.','d','l','l',0},
746 {'d','x','d','i','a','g','n','.','d','l','l',0},
747 {'q','u','a','r','t','z','.','d','l','l',0}
751 WCHAR szFilePath[MAX_PATH];
754 GetSystemDirectoryW(szFilePath, MAX_PATH);
756 for (i = 0; i < sizeof(dlls) / sizeof(dlls[0]); i++)
758 static const WCHAR szFormat[] = {'%','d',0};
761 IDxDiagContainerImpl_Container *file_container;
763 snprintfW(szFileID, sizeof(szFileID)/sizeof(szFileID[0]), szFormat, i);
765 file_container = allocate_information_node(szFileID);
767 return E_OUTOFMEMORY;
769 hr = fill_file_description(file_container, szFilePath, dlls[i]);
772 free_information_tree(file_container);
776 add_subcontainer(node, file_container);
782 static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
784 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
785 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
789 VariantInit(friendly_name);
790 VariantInit(clsid_name);
792 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
796 hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
799 VariantClear(friendly_name);
806 static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
808 static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
809 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
810 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
811 static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
812 static const WCHAR szVersionFormat[] = {'v','%','d',0};
815 IFilterMapper2 *pFileMapper = NULL;
816 IAMFilterData *pFilterData = NULL;
817 REGFILTER2 *pRF = NULL;
820 DWORD dwNOutputs = 0;
823 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
824 (void **)&pFileMapper);
828 hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
832 hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, (BYTE **)&pRF);
836 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szVersionFormat, pRF->dwVersion);
837 hr = add_bstr_property(subcont, szVersionW, bufferW);
841 if (pRF->dwVersion == 1)
843 for (j = 0; j < pRF->u.s.cPins; j++)
844 if (pRF->u.s.rgPins[j].bOutput)
849 else if (pRF->dwVersion == 2)
851 for (j = 0; j < pRF->u.s1.cPins2; j++)
852 if (pRF->u.s1.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
858 hr = add_ui4_property(subcont, dwInputs, dwNInputs);
862 hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
866 hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
873 if (pFilterData) IAMFilterData_Release(pFilterData);
874 if (pFileMapper) IFilterMapper2_Release(pFileMapper);
879 static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
881 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
882 static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
883 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
886 IPropertyBag *pPropFilterBag = NULL;
888 VARIANT friendly_name;
892 VariantInit(&friendly_name);
893 VariantInit(&clsid_name);
896 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
900 hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
904 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
905 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
907 hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
911 hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
915 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
919 hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
923 hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
924 SafeArrayUnaccessData(V_ARRAY(&v));
931 VariantClear(&clsid_name);
932 VariantClear(&friendly_name);
933 if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
938 static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
940 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
941 static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
942 static const WCHAR szIdFormat[] = {'%','d',0};
946 ICreateDevEnum *pCreateDevEnum;
947 IEnumMoniker *pEmCat = NULL;
948 IMoniker *pMCat = NULL;
949 IEnumMoniker *pEnum = NULL;
951 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
952 &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
956 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
960 while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
964 IPropertyBag *pPropBag;
966 IMoniker *pMoniker = NULL;
968 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
971 IMoniker_Release(pMCat);
975 hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
976 IPropertyBag_Release(pPropBag);
979 IMoniker_Release(pMCat);
983 hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
986 IMoniker_Release(pMCat);
987 VariantClear(&vCatClsid);
988 VariantClear(&vCatName);
992 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
995 IMoniker_Release(pMCat);
996 VariantClear(&vCatClsid);
997 VariantClear(&vCatName);
1001 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1003 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1006 IDxDiagContainerImpl_Container *subcont;
1008 snprintfW(bufferW, sizeof(bufferW)/sizeof(bufferW[0]), szIdFormat, i);
1009 subcont = allocate_information_node(bufferW);
1013 IMoniker_Release(pMoniker);
1017 hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1020 free_information_tree(subcont);
1021 IMoniker_Release(pMoniker);
1025 hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1028 free_information_tree(subcont);
1029 IMoniker_Release(pMoniker);
1033 hr = fill_filter_container(subcont, pMoniker);
1036 free_information_tree(subcont);
1037 IMoniker_Release(pMoniker);
1041 add_subcontainer(node, subcont);
1043 IMoniker_Release(pMoniker);
1046 IEnumMoniker_Release(pEnum);
1047 IMoniker_Release(pMCat);
1048 VariantClear(&vCatClsid);
1049 VariantClear(&vCatName);
1056 if (pEmCat) IEnumMoniker_Release(pEmCat);
1057 ICreateDevEnum_Release(pCreateDevEnum);
1061 static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1066 static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1068 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1069 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};
1070 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1071 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1072 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1073 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1074 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};
1075 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1076 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};
1077 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1082 HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1085 {DxDiag_SystemInfo, build_systeminfo_tree},
1086 {DxDiag_DisplayDevices, build_displaydevices_tree},
1087 {DxDiag_DirectSound, build_directsound_tree},
1088 {DxDiag_DirectMusic, build_directmusic_tree},
1089 {DxDiag_DirectInput, build_directinput_tree},
1090 {DxDiag_DirectPlay, build_directplay_tree},
1091 {DxDiag_SystemDevices, build_systemdevices_tree},
1092 {DxDiag_DirectXFiles, build_directxfiles_tree},
1093 {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1094 {DxDiag_LogicalDisks, build_logicaldisks_tree},
1097 IDxDiagContainerImpl_Container *info_root;
1100 info_root = allocate_information_node(NULL);
1102 return E_OUTOFMEMORY;
1104 for (index = 0; index < sizeof(root_children)/sizeof(root_children[0]); index++)
1106 IDxDiagContainerImpl_Container *node;
1109 node = allocate_information_node(root_children[index].name);
1112 free_information_tree(info_root);
1113 return E_OUTOFMEMORY;
1116 hr = root_children[index].initfunc(node);
1119 free_information_tree(node);
1120 free_information_tree(info_root);
1124 add_subcontainer(info_root, node);
1127 *pinfo_root = info_root;