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
fill_language_information(IDxDiagContainerImpl_Container
*node
)
351 static const WCHAR regional_setting_engW
[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
352 static const WCHAR languages_fmtW
[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
353 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};
354 static const WCHAR szLanguagesEnglish
[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
356 WCHAR system_lang
[80], regional_setting
[100], user_lang
[80], language_str
[300];
359 /* szLanguagesLocalized */
360 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SNATIVELANGNAME
, system_lang
, sizeof(system_lang
)/sizeof(WCHAR
));
361 LoadStringW(dxdiagn_instance
, IDS_REGIONAL_SETTING
, regional_setting
, sizeof(regional_setting
)/sizeof(WCHAR
));
362 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SNATIVELANGNAME
, user_lang
, sizeof(user_lang
)/sizeof(WCHAR
));
364 snprintfW(language_str
, sizeof(language_str
)/sizeof(WCHAR
), languages_fmtW
, system_lang
, regional_setting
, user_lang
);
366 hr
= add_bstr_property(node
, szLanguagesLocalized
, language_str
);
370 /* szLanguagesEnglish */
371 GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT
, LOCALE_SENGLANGUAGE
, system_lang
, sizeof(system_lang
)/sizeof(WCHAR
));
372 GetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SENGLANGUAGE
, user_lang
, sizeof(user_lang
)/sizeof(WCHAR
));
374 snprintfW(language_str
, sizeof(language_str
)/sizeof(WCHAR
), languages_fmtW
, system_lang
, regional_setting_engW
, user_lang
);
376 hr
= add_bstr_property(node
, szLanguagesEnglish
, language_str
);
383 static HRESULT
build_systeminfo_tree(IDxDiagContainerImpl_Container
*node
)
385 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};
386 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};
387 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};
388 static const WCHAR szDirectXVersionLetter_v
[] = {'c',0};
389 static const WCHAR bDebug
[] = {'b','D','e','b','u','g',0};
390 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};
391 static const WCHAR szDirectXVersionEnglish_v
[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
392 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};
393 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};
394 static const WCHAR ullPhysicalMemory
[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
395 static const WCHAR ullUsedPageFile
[] = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
396 static const WCHAR ullAvailPageFile
[] = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
397 static const WCHAR szWindowsDir
[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
398 static const WCHAR dwOSMajorVersion
[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
399 static const WCHAR dwOSMinorVersion
[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
400 static const WCHAR dwOSBuildNumber
[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
401 static const WCHAR dwOSPlatformID
[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
402 static const WCHAR szCSDVersion
[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
403 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};
404 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};
410 WCHAR buffer
[MAX_PATH
], computer_name
[MAX_COMPUTERNAME_LENGTH
+ 1];
412 hr
= add_ui4_property(node
, dwDirectXVersionMajor
, 9);
416 hr
= add_ui4_property(node
, dwDirectXVersionMinor
, 0);
420 hr
= add_bstr_property(node
, szDirectXVersionLetter
, szDirectXVersionLetter_v
);
424 hr
= add_bstr_property(node
, szDirectXVersionEnglish
, szDirectXVersionEnglish_v
);
428 hr
= add_bstr_property(node
, szDirectXVersionLongEnglish
, szDirectXVersionLongEnglish_v
);
432 hr
= add_bool_property(node
, bDebug
, FALSE
);
436 msex
.dwLength
= sizeof(msex
);
437 GlobalMemoryStatusEx(&msex
);
439 hr
= add_ull_as_bstr_property(node
, ullPhysicalMemory
, msex
.ullTotalPhys
);
443 hr
= add_ull_as_bstr_property(node
, ullUsedPageFile
, msex
.ullTotalPageFile
- msex
.ullAvailPageFile
);
447 hr
= add_ull_as_bstr_property(node
, ullAvailPageFile
, msex
.ullAvailPageFile
);
451 info
.dwOSVersionInfoSize
= sizeof(info
);
452 GetVersionExW(&info
);
454 hr
= add_ui4_property(node
, dwOSMajorVersion
, info
.dwMajorVersion
);
458 hr
= add_ui4_property(node
, dwOSMinorVersion
, info
.dwMinorVersion
);
462 hr
= add_ui4_property(node
, dwOSBuildNumber
, info
.dwBuildNumber
);
466 hr
= add_ui4_property(node
, dwOSPlatformID
, info
.dwPlatformId
);
470 hr
= add_bstr_property(node
, szCSDVersion
, info
.szCSDVersion
);
474 GetWindowsDirectoryW(buffer
, MAX_PATH
);
476 hr
= add_bstr_property(node
, szWindowsDir
, buffer
);
480 count
= sizeof(computer_name
)/sizeof(WCHAR
);
481 if (!GetComputerNameW(computer_name
, &count
))
484 hr
= add_bstr_property(node
, szMachineNameLocalized
, computer_name
);
488 hr
= add_bstr_property(node
, szMachineNameEnglish
, computer_name
);
492 hr
= fill_language_information(node
);
499 static HRESULT
build_displaydevices_tree(IDxDiagContainerImpl_Container
*node
)
501 static const WCHAR szDescription
[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
502 static const WCHAR szDeviceName
[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
503 static const WCHAR szKeyDeviceID
[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
504 static const WCHAR szKeyDeviceKey
[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
505 static const WCHAR szVendorId
[] = {'s','z','V','e','n','d','o','r','I','d',0};
506 static const WCHAR szDeviceId
[] = {'s','z','D','e','v','i','c','e','I','d',0};
507 static const WCHAR szDeviceIdentifier
[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
508 static const WCHAR dwWidth
[] = {'d','w','W','i','d','t','h',0};
509 static const WCHAR dwHeight
[] = {'d','w','H','e','i','g','h','t',0};
510 static const WCHAR dwBpp
[] = {'d','w','B','p','p',0};
511 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};
512 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};
514 static const WCHAR szAdapterID
[] = {'0',0};
515 static const WCHAR szEmpty
[] = {0};
517 IDxDiagContainerImpl_Container
*display_adapter
;
519 IDirectDraw7
*pDirectDraw
;
521 DISPLAY_DEVICEW disp_dev
;
522 DDSURFACEDESC2 surface_descr
;
526 display_adapter
= allocate_information_node(szAdapterID
);
527 if (!display_adapter
)
528 return E_OUTOFMEMORY
;
530 add_subcontainer(node
, display_adapter
);
532 disp_dev
.cb
= sizeof(disp_dev
);
533 if (EnumDisplayDevicesW( NULL
, 0, &disp_dev
, 0 ))
535 hr
= add_bstr_property(display_adapter
, szDeviceName
, disp_dev
.DeviceName
);
539 hr
= add_bstr_property(display_adapter
, szDescription
, disp_dev
.DeviceString
);
544 /* For now, silently ignore a failure from DirectDrawCreateEx. */
545 hr
= DirectDrawCreateEx(NULL
, (LPVOID
*)&pDirectDraw
, &IID_IDirectDraw7
, NULL
);
549 dd_caps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
550 dd_caps
.dwCaps2
= dd_caps
.dwCaps3
= dd_caps
.dwCaps4
= 0;
551 hr
= IDirectDraw7_GetAvailableVidMem(pDirectDraw
, &dd_caps
, &tmp
, NULL
);
554 static const WCHAR mem_fmt
[] = {'%','.','1','f',' ','M','B',0};
556 snprintfW(buffer
, sizeof(buffer
)/sizeof(buffer
[0]), mem_fmt
, ((float)tmp
) / 1000000.0);
558 hr
= add_bstr_property(display_adapter
, szDisplayMemoryLocalized
, buffer
);
562 hr
= add_bstr_property(display_adapter
, szDisplayMemoryEnglish
, buffer
);
567 surface_descr
.dwSize
= sizeof(surface_descr
);
568 hr
= IDirectDraw7_GetDisplayMode(pDirectDraw
, &surface_descr
);
571 if (surface_descr
.dwFlags
& DDSD_WIDTH
)
573 hr
= add_ui4_property(display_adapter
, dwWidth
, surface_descr
.dwWidth
);
578 if (surface_descr
.dwFlags
& DDSD_HEIGHT
)
580 hr
= add_ui4_property(display_adapter
, dwHeight
, surface_descr
.dwHeight
);
585 if (surface_descr
.dwFlags
& DDSD_PIXELFORMAT
)
587 hr
= add_ui4_property(display_adapter
, dwBpp
, surface_descr
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
);
593 get_display_device_id(buffer
);
595 hr
= add_bstr_property(display_adapter
, szDeviceIdentifier
, buffer
);
599 hr
= add_bstr_property(display_adapter
, szVendorId
, szEmpty
);
603 hr
= add_bstr_property(display_adapter
, szDeviceId
, szEmpty
);
607 hr
= add_bstr_property(display_adapter
, szKeyDeviceKey
, szEmpty
);
611 hr
= add_bstr_property(display_adapter
, szKeyDeviceID
, szEmpty
);
617 IDirectDraw7_Release(pDirectDraw
);
621 static HRESULT
build_directsound_tree(IDxDiagContainerImpl_Container
*node
)
623 static const WCHAR DxDiag_SoundDevices
[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
624 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};
626 IDxDiagContainerImpl_Container
*cont
;
628 cont
= allocate_information_node(DxDiag_SoundDevices
);
630 return E_OUTOFMEMORY
;
632 add_subcontainer(node
, cont
);
634 cont
= allocate_information_node(DxDiag_SoundCaptureDevices
);
636 return E_OUTOFMEMORY
;
638 add_subcontainer(node
, cont
);
643 static HRESULT
build_directmusic_tree(IDxDiagContainerImpl_Container
*node
)
648 static HRESULT
build_directinput_tree(IDxDiagContainerImpl_Container
*node
)
653 static HRESULT
build_directplay_tree(IDxDiagContainerImpl_Container
*node
)
658 static HRESULT
build_systemdevices_tree(IDxDiagContainerImpl_Container
*node
)
663 static HRESULT
fill_file_description(IDxDiagContainerImpl_Container
*node
, const WCHAR
*szFilePath
, const WCHAR
*szFileName
)
665 static const WCHAR szSlashSep
[] = {'\\',0};
666 static const WCHAR szPath
[] = {'s','z','P','a','t','h',0};
667 static const WCHAR szName
[] = {'s','z','N','a','m','e',0};
668 static const WCHAR szVersion
[] = {'s','z','V','e','r','s','i','o','n',0};
669 static const WCHAR szAttributes
[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
670 static const WCHAR szLanguageEnglish
[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
671 static const WCHAR dwFileTimeHigh
[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
672 static const WCHAR dwFileTimeLow
[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
673 static const WCHAR bBeta
[] = {'b','B','e','t','a',0};
674 static const WCHAR bDebug
[] = {'b','D','e','b','u','g',0};
675 static const WCHAR bExists
[] = {'b','E','x','i','s','t','s',0};
678 static const WCHAR szFinal_Retail_v
[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
679 static const WCHAR szEnglish_v
[] = {'E','n','g','l','i','s','h',0};
680 static const WCHAR szVersionFormat
[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
684 WCHAR szVersion_v
[1024];
686 void *pVersionInfo
= NULL
;
687 BOOL boolret
= FALSE
;
689 VS_FIXEDFILEINFO
*pFileInfo
;
691 TRACE("Filling container %p for %s in %s\n", node
,
692 debugstr_w(szFileName
), debugstr_w(szFilePath
));
694 szFile
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (lstrlenW(szFilePath
) +
695 lstrlenW(szFileName
) + 2 /* slash + terminator */));
697 return E_OUTOFMEMORY
;
699 lstrcpyW(szFile
, szFilePath
);
700 lstrcatW(szFile
, szSlashSep
);
701 lstrcatW(szFile
, szFileName
);
703 retval
= GetFileVersionInfoSizeW(szFile
, &hdl
);
706 pVersionInfo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, retval
);
713 if (GetFileVersionInfoW(szFile
, 0, retval
, pVersionInfo
) &&
714 VerQueryValueW(pVersionInfo
, szSlashSep
, (void **)&pFileInfo
, &uiLength
))
718 hr
= add_bstr_property(node
, szPath
, szFile
);
722 hr
= add_bstr_property(node
, szName
, szFileName
);
726 hr
= add_bool_property(node
, bExists
, boolret
);
732 snprintfW(szVersion_v
, sizeof(szVersion_v
)/sizeof(szVersion_v
[0]),
734 HIWORD(pFileInfo
->dwFileVersionMS
),
735 LOWORD(pFileInfo
->dwFileVersionMS
),
736 HIWORD(pFileInfo
->dwFileVersionLS
),
737 LOWORD(pFileInfo
->dwFileVersionLS
));
739 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v
));
741 hr
= add_bstr_property(node
, szVersion
, szVersion_v
);
745 hr
= add_bstr_property(node
, szAttributes
, szFinal_Retail_v
);
749 hr
= add_bstr_property(node
, szLanguageEnglish
, szEnglish_v
);
753 hr
= add_ui4_property(node
, dwFileTimeHigh
, pFileInfo
->dwFileDateMS
);
757 hr
= add_ui4_property(node
, dwFileTimeLow
, pFileInfo
->dwFileDateLS
);
761 hr
= add_bool_property(node
, bBeta
, ((pFileInfo
->dwFileFlags
& pFileInfo
->dwFileFlagsMask
) & VS_FF_PRERELEASE
) != 0);
765 hr
= add_bool_property(node
, bDebug
, ((pFileInfo
->dwFileFlags
& pFileInfo
->dwFileFlagsMask
) & VS_FF_DEBUG
) != 0);
772 HeapFree(GetProcessHeap(), 0, pVersionInfo
);
773 HeapFree(GetProcessHeap(), 0, szFile
);
777 static HRESULT
build_directxfiles_tree(IDxDiagContainerImpl_Container
*node
)
779 static const WCHAR dlls
[][15] =
781 {'d','3','d','8','.','d','l','l',0},
782 {'d','3','d','9','.','d','l','l',0},
783 {'d','d','r','a','w','.','d','l','l',0},
784 {'d','e','v','e','n','u','m','.','d','l','l',0},
785 {'d','i','n','p','u','t','8','.','d','l','l',0},
786 {'d','i','n','p','u','t','.','d','l','l',0},
787 {'d','m','b','a','n','d','.','d','l','l',0},
788 {'d','m','c','o','m','p','o','s','.','d','l','l',0},
789 {'d','m','i','m','e','.','d','l','l',0},
790 {'d','m','l','o','a','d','e','r','.','d','l','l',0},
791 {'d','m','s','c','r','i','p','t','.','d','l','l',0},
792 {'d','m','s','t','y','l','e','.','d','l','l',0},
793 {'d','m','s','y','n','t','h','.','d','l','l',0},
794 {'d','m','u','s','i','c','.','d','l','l',0},
795 {'d','p','l','a','y','x','.','d','l','l',0},
796 {'d','p','n','e','t','.','d','l','l',0},
797 {'d','s','o','u','n','d','.','d','l','l',0},
798 {'d','s','w','a','v','e','.','d','l','l',0},
799 {'d','x','d','i','a','g','n','.','d','l','l',0},
800 {'q','u','a','r','t','z','.','d','l','l',0}
804 WCHAR szFilePath
[MAX_PATH
];
807 GetSystemDirectoryW(szFilePath
, MAX_PATH
);
809 for (i
= 0; i
< sizeof(dlls
) / sizeof(dlls
[0]); i
++)
811 static const WCHAR szFormat
[] = {'%','d',0};
814 IDxDiagContainerImpl_Container
*file_container
;
816 snprintfW(szFileID
, sizeof(szFileID
)/sizeof(szFileID
[0]), szFormat
, i
);
818 file_container
= allocate_information_node(szFileID
);
820 return E_OUTOFMEMORY
;
822 hr
= fill_file_description(file_container
, szFilePath
, dlls
[i
]);
825 free_information_tree(file_container
);
829 add_subcontainer(node
, file_container
);
835 static HRESULT
read_property_names(IPropertyBag
*pPropBag
, VARIANT
*friendly_name
, VARIANT
*clsid_name
)
837 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
838 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
842 VariantInit(friendly_name
);
843 VariantInit(clsid_name
);
845 hr
= IPropertyBag_Read(pPropBag
, wszFriendlyName
, friendly_name
, 0);
849 hr
= IPropertyBag_Read(pPropBag
, wszClsidName
, clsid_name
, 0);
852 VariantClear(friendly_name
);
859 static HRESULT
fill_filter_data_information(IDxDiagContainerImpl_Container
*subcont
, BYTE
*pData
, ULONG cb
)
861 static const WCHAR szVersionW
[] = {'s','z','V','e','r','s','i','o','n',0};
862 static const WCHAR dwInputs
[] = {'d','w','I','n','p','u','t','s',0};
863 static const WCHAR dwOutputs
[] = {'d','w','O','u','t','p','u','t','s',0};
864 static const WCHAR dwMeritW
[] = {'d','w','M','e','r','i','t',0};
865 static const WCHAR szVersionFormat
[] = {'v','%','d',0};
868 IFilterMapper2
*pFileMapper
= NULL
;
869 IAMFilterData
*pFilterData
= NULL
;
870 REGFILTER2
*pRF
= NULL
;
873 DWORD dwNOutputs
= 0;
876 hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC
, &IID_IFilterMapper2
,
877 (void **)&pFileMapper
);
881 hr
= IFilterMapper2_QueryInterface(pFileMapper
, &IID_IAMFilterData
, (void **)&pFilterData
);
885 hr
= IAMFilterData_ParseFilterData(pFilterData
, pData
, cb
, (BYTE
**)&pRF
);
889 snprintfW(bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), szVersionFormat
, pRF
->dwVersion
);
890 hr
= add_bstr_property(subcont
, szVersionW
, bufferW
);
894 if (pRF
->dwVersion
== 1)
896 for (j
= 0; j
< pRF
->u
.s
.cPins
; j
++)
897 if (pRF
->u
.s
.rgPins
[j
].bOutput
)
902 else if (pRF
->dwVersion
== 2)
904 for (j
= 0; j
< pRF
->u
.s1
.cPins2
; j
++)
905 if (pRF
->u
.s1
.rgPins2
[j
].dwFlags
& REG_PINFLAG_B_OUTPUT
)
911 hr
= add_ui4_property(subcont
, dwInputs
, dwNInputs
);
915 hr
= add_ui4_property(subcont
, dwOutputs
, dwNOutputs
);
919 hr
= add_ui4_property(subcont
, dwMeritW
, pRF
->dwMerit
);
926 if (pFilterData
) IAMFilterData_Release(pFilterData
);
927 if (pFileMapper
) IFilterMapper2_Release(pFileMapper
);
932 static HRESULT
fill_filter_container(IDxDiagContainerImpl_Container
*subcont
, IMoniker
*pMoniker
)
934 static const WCHAR szName
[] = {'s','z','N','a','m','e',0};
935 static const WCHAR ClsidFilterW
[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
936 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
939 IPropertyBag
*pPropFilterBag
= NULL
;
941 VARIANT friendly_name
;
945 VariantInit(&friendly_name
);
946 VariantInit(&clsid_name
);
949 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (void **)&pPropFilterBag
);
953 hr
= read_property_names(pPropFilterBag
, &friendly_name
, &clsid_name
);
957 TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name
)));
958 TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name
)));
960 hr
= add_bstr_property(subcont
, szName
, V_BSTR(&friendly_name
));
964 hr
= add_bstr_property(subcont
, ClsidFilterW
, V_BSTR(&clsid_name
));
968 hr
= IPropertyBag_Read(pPropFilterBag
, wszFilterDataName
, &v
, NULL
);
972 hr
= SafeArrayAccessData(V_ARRAY(&v
), (void **)&pData
);
976 hr
= fill_filter_data_information(subcont
, pData
, V_ARRAY(&v
)->rgsabound
->cElements
);
977 SafeArrayUnaccessData(V_ARRAY(&v
));
984 VariantClear(&clsid_name
);
985 VariantClear(&friendly_name
);
986 if (pPropFilterBag
) IPropertyBag_Release(pPropFilterBag
);
991 static HRESULT
build_directshowfilters_tree(IDxDiagContainerImpl_Container
*node
)
993 static const WCHAR szCatName
[] = {'s','z','C','a','t','N','a','m','e',0};
994 static const WCHAR ClsidCatW
[] = {'C','l','s','i','d','C','a','t',0};
995 static const WCHAR szIdFormat
[] = {'%','d',0};
999 ICreateDevEnum
*pCreateDevEnum
;
1000 IEnumMoniker
*pEmCat
= NULL
;
1001 IMoniker
*pMCat
= NULL
;
1002 IEnumMoniker
*pEnum
= NULL
;
1004 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC_SERVER
,
1005 &IID_ICreateDevEnum
, (void **)&pCreateDevEnum
);
1009 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEmCat
, 0);
1013 while (IEnumMoniker_Next(pEmCat
, 1, &pMCat
, NULL
) == S_OK
)
1017 IPropertyBag
*pPropBag
;
1019 IMoniker
*pMoniker
= NULL
;
1021 hr
= IMoniker_BindToStorage(pMCat
, NULL
, NULL
, &IID_IPropertyBag
, (void **)&pPropBag
);
1024 IMoniker_Release(pMCat
);
1028 hr
= read_property_names(pPropBag
, &vCatName
, &vCatClsid
);
1029 IPropertyBag_Release(pPropBag
);
1032 IMoniker_Release(pMCat
);
1036 hr
= CLSIDFromString(V_BSTR(&vCatClsid
), &clsidCat
);
1039 IMoniker_Release(pMCat
);
1040 VariantClear(&vCatClsid
);
1041 VariantClear(&vCatName
);
1045 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
1048 IMoniker_Release(pMCat
);
1049 VariantClear(&vCatClsid
);
1050 VariantClear(&vCatName
);
1054 TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat
));
1056 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
1059 IDxDiagContainerImpl_Container
*subcont
;
1061 snprintfW(bufferW
, sizeof(bufferW
)/sizeof(bufferW
[0]), szIdFormat
, i
);
1062 subcont
= allocate_information_node(bufferW
);
1066 IMoniker_Release(pMoniker
);
1070 hr
= add_bstr_property(subcont
, szCatName
, V_BSTR(&vCatName
));
1073 free_information_tree(subcont
);
1074 IMoniker_Release(pMoniker
);
1078 hr
= add_bstr_property(subcont
, ClsidCatW
, V_BSTR(&vCatClsid
));
1081 free_information_tree(subcont
);
1082 IMoniker_Release(pMoniker
);
1086 hr
= fill_filter_container(subcont
, pMoniker
);
1089 free_information_tree(subcont
);
1090 IMoniker_Release(pMoniker
);
1094 add_subcontainer(node
, subcont
);
1096 IMoniker_Release(pMoniker
);
1099 IEnumMoniker_Release(pEnum
);
1100 IMoniker_Release(pMCat
);
1101 VariantClear(&vCatClsid
);
1102 VariantClear(&vCatName
);
1109 if (pEmCat
) IEnumMoniker_Release(pEmCat
);
1110 ICreateDevEnum_Release(pCreateDevEnum
);
1114 static HRESULT
build_logicaldisks_tree(IDxDiagContainerImpl_Container
*node
)
1119 static HRESULT
build_information_tree(IDxDiagContainerImpl_Container
**pinfo_root
)
1121 static const WCHAR DxDiag_SystemInfo
[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1122 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};
1123 static const WCHAR DxDiag_DirectSound
[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1124 static const WCHAR DxDiag_DirectMusic
[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1125 static const WCHAR DxDiag_DirectInput
[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1126 static const WCHAR DxDiag_DirectPlay
[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1127 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};
1128 static const WCHAR DxDiag_DirectXFiles
[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1129 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};
1130 static const WCHAR DxDiag_LogicalDisks
[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1135 HRESULT (*initfunc
)(IDxDiagContainerImpl_Container
*);
1138 {DxDiag_SystemInfo
, build_systeminfo_tree
},
1139 {DxDiag_DisplayDevices
, build_displaydevices_tree
},
1140 {DxDiag_DirectSound
, build_directsound_tree
},
1141 {DxDiag_DirectMusic
, build_directmusic_tree
},
1142 {DxDiag_DirectInput
, build_directinput_tree
},
1143 {DxDiag_DirectPlay
, build_directplay_tree
},
1144 {DxDiag_SystemDevices
, build_systemdevices_tree
},
1145 {DxDiag_DirectXFiles
, build_directxfiles_tree
},
1146 {DxDiag_DirectShowFilters
, build_directshowfilters_tree
},
1147 {DxDiag_LogicalDisks
, build_logicaldisks_tree
},
1150 IDxDiagContainerImpl_Container
*info_root
;
1153 info_root
= allocate_information_node(NULL
);
1155 return E_OUTOFMEMORY
;
1157 for (index
= 0; index
< sizeof(root_children
)/sizeof(root_children
[0]); index
++)
1159 IDxDiagContainerImpl_Container
*node
;
1162 node
= allocate_information_node(root_children
[index
].name
);
1165 free_information_tree(info_root
);
1166 return E_OUTOFMEMORY
;
1169 hr
= root_children
[index
].initfunc(node
);
1172 free_information_tree(node
);
1173 free_information_tree(info_root
);
1177 add_subcontainer(info_root
, node
);
1180 *pinfo_root
= info_root
;