xref: /reactos/dll/directx/wine/dxdiagn/provider.c (revision d6c879a0)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * IDxDiagProvider Implementation
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2004-2005 Raphael Junqueira
5c2c66affSColin Finck  * Copyright 2010 Andrew Nguyen
6c2c66affSColin Finck  *
7c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck  *
12c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15c2c66affSColin Finck  * Lesser General Public License for more details.
16c2c66affSColin Finck  *
17c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck  *
21c2c66affSColin Finck  */
22c2c66affSColin Finck 
23c2c66affSColin Finck 
24afc3201bSAmine Khaldi #define COBJMACROS
25afc3201bSAmine Khaldi #define NONAMELESSUNION
26afc3201bSAmine Khaldi #define NONAMELESSSTRUCT
27*d6c879a0SAmine Khaldi 
28*d6c879a0SAmine Khaldi #ifdef __REACTOS__
29*d6c879a0SAmine Khaldi #include <wchar.h>
30*d6c879a0SAmine Khaldi #endif
31*d6c879a0SAmine Khaldi 
32afc3201bSAmine Khaldi #include "dxdiag_private.h"
33afc3201bSAmine Khaldi #include "winver.h"
34afc3201bSAmine Khaldi #include "objidl.h"
35afc3201bSAmine Khaldi #include "uuids.h"
36afc3201bSAmine Khaldi #include "vfw.h"
37afc3201bSAmine Khaldi #include "mmddk.h"
38afc3201bSAmine Khaldi #include "d3d9.h"
39afc3201bSAmine Khaldi #include "strmif.h"
40afc3201bSAmine Khaldi #include "initguid.h"
41*d6c879a0SAmine Khaldi #include "wine/fil_data.h"
42afc3201bSAmine Khaldi #include "psapi.h"
43afc3201bSAmine Khaldi #include "wbemcli.h"
44afc3201bSAmine Khaldi #include "dsound.h"
45afc3201bSAmine Khaldi 
46afc3201bSAmine Khaldi #include "wine/debug.h"
47afc3201bSAmine Khaldi 
48afc3201bSAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
49c2c66affSColin Finck 
50c2c66affSColin Finck static const WCHAR szEmpty[] = {0};
51c2c66affSColin Finck 
52c2c66affSColin Finck static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root);
53c2c66affSColin Finck static void free_information_tree(IDxDiagContainerImpl_Container *node);
54c2c66affSColin Finck 
55c2c66affSColin Finck static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
56c2c66affSColin Finck static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
57c2c66affSColin Finck static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
58c2c66affSColin Finck static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
59c2c66affSColin Finck static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
60c2c66affSColin Finck static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
61c2c66affSColin Finck static const WCHAR szDeviceIdentifier[] = {'s','z','D','e','v','i','c','e','I','d','e','n','t','i','f','i','e','r',0};
62c2c66affSColin Finck static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
63c2c66affSColin Finck static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
64c2c66affSColin Finck static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
65c2c66affSColin Finck 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};
66c2c66affSColin Finck 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};
67afc3201bSAmine Khaldi static const WCHAR szDisplayModeLocalized[] = {'s','z','D','i','s','p','l','a','y','M','o','d','e','L','o','c','a','l','i','z','e','d',0};
68afc3201bSAmine Khaldi static const WCHAR szDisplayModeEnglish[] = {'s','z','D','i','s','p','l','a','y','M','o','d','e','E','n','g','l','i','s','h',0};
69c2c66affSColin Finck static const WCHAR szDriverName[] = {'s','z','D','r','i','v','e','r','N','a','m','e',0};
70c2c66affSColin Finck static const WCHAR szDriverVersion[] = {'s','z','D','r','i','v','e','r','V','e','r','s','i','o','n',0};
71c2c66affSColin Finck static const WCHAR szSubSysId[] = {'s','z','S','u','b','S','y','s','I','d',0};
72c2c66affSColin Finck static const WCHAR szRevisionId[] = {'s','z','R','e','v','i','s','i','o','n','I','d',0};
73c2c66affSColin Finck static const WCHAR dwRefreshRate[] = {'d','w','R','e','f','r','e','s','h','R','a','t','e',0};
74c2c66affSColin Finck static const WCHAR szManufacturer[] = {'s','z','M','a','n','u','f','a','c','t','u','r','e','r',0};
75c2c66affSColin Finck static const WCHAR szChipType[] = {'s','z','C','h','i','p','T','y','p','e',0};
76c2c66affSColin Finck static const WCHAR szDACType[] = {'s','z','D','A','C','T','y','p','e',0};
77c2c66affSColin Finck static const WCHAR szRevision[] = {'s','z','R','e','v','i','s','i','o','n',0};
78afc3201bSAmine Khaldi static const WCHAR szMonitorName[] = {'s','z','M','o','n','i','t','o','r','N','a','m','e',0};
79afc3201bSAmine Khaldi static const WCHAR szMonitorMaxRes[] = {'s','z','M','o','n','i','t','o','r','M','a','x','R','e','s',0};
80afc3201bSAmine Khaldi static const WCHAR szDriverAttributes[] = {'s','z','D','r','i','v','e','r','A','t','t','r','i','b','u','t','e','s',0};
81afc3201bSAmine Khaldi static const WCHAR szDriverLanguageEnglish[] = {'s','z','D','r','i','v','e','r','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
82afc3201bSAmine Khaldi static const WCHAR szDriverLanguageLocalized[] = {'s','z','D','r','i','v','e','r','L','a','n','g','u','a','g','e','L','o','c','a','l','i','z','e','d',0};
83afc3201bSAmine Khaldi static const WCHAR szDriverDateEnglish[] = {'s','z','D','r','i','v','e','r','D','a','t','e','E','n','g','l','i','s','h',0};
84afc3201bSAmine Khaldi static const WCHAR szDriverDateLocalized[] = {'s','z','D','r','i','v','e','r','D','a','t','e','L','o','c','a','l','i','z','e','d',0};
85afc3201bSAmine Khaldi static const WCHAR lDriverSize[] = {'l','D','r','i','v','e','r','S','i','z','e',0};
86afc3201bSAmine Khaldi static const WCHAR szMiniVdd[] = {'s','z','M','i','n','i','V','d','d',0};
87afc3201bSAmine Khaldi static const WCHAR szMiniVddDateLocalized[] = {'s','z','M','i','n','i','V','d','d','D','a','t','e','L','o','c','a','l','i','z','e','d',0};
88afc3201bSAmine Khaldi static const WCHAR szMiniVddDateEnglish[] = {'s','z','M','i','n','i','V','d','d','D','a','t','e','E','n','g','l','i','s','h',0};
89afc3201bSAmine Khaldi static const WCHAR lMiniVddSize[] = {'l','M','i','n','i','V','d','d','S','i','z','e',0};
90afc3201bSAmine Khaldi static const WCHAR szVdd[] = {'s','z','V','d','d',0};
91afc3201bSAmine Khaldi static const WCHAR bCanRenderWindow[] = {'b','C','a','n','R','e','n','d','e','r','W','i','n','d','o','w',0};
92afc3201bSAmine Khaldi static const WCHAR bDriverBeta[] = {'b','D','r','i','v','e','r','B','e','t','a',0};
93afc3201bSAmine Khaldi static const WCHAR bDriverDebug[] = {'b','D','r','i','v','e','r','D','e','b','u','g',0};
94afc3201bSAmine Khaldi static const WCHAR bDriverSigned[] = {'b','D','r','i','v','e','r','S','i','g','n','e','d',0};
95afc3201bSAmine Khaldi static const WCHAR bDriverSignedValid[] = {'b','D','r','i','v','e','r','S','i','g','n','e','d','V','a','l','i','d',0};
96afc3201bSAmine Khaldi static const WCHAR szDriverSignDate[] = {'s','z','D','r','i','v','e','r','S','i','g','n','D','a','t','e',0};
97afc3201bSAmine Khaldi static const WCHAR dwDDIVersion[] = {'d','w','D','D','I','V','e','r','s','i','o','n',0};
98afc3201bSAmine Khaldi static const WCHAR szDDIVersionEnglish[] = {'s','z','D','D','I','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
99afc3201bSAmine Khaldi static const WCHAR szDDIVersionLocalized[] = {'s','z','D','D','I','V','e','r','s','i','o','n','L','o','c','a','l','i','z','e','d',0};
100afc3201bSAmine Khaldi static const WCHAR iAdapter[] = {'i','A','d','a','p','t','e','r',0};
101afc3201bSAmine Khaldi static const WCHAR dwWHQLLevel[] = {'d','w','W','H','Q','L','L','e','v','e','l',0};
102c2c66affSColin Finck 
103c2c66affSColin Finck struct IDxDiagProviderImpl
104c2c66affSColin Finck {
105c2c66affSColin Finck   IDxDiagProvider IDxDiagProvider_iface;
106c2c66affSColin Finck   LONG ref;
107c2c66affSColin Finck   BOOL init;
108c2c66affSColin Finck   DXDIAG_INIT_PARAMS params;
109c2c66affSColin Finck   IDxDiagContainerImpl_Container *info_root;
110c2c66affSColin Finck };
111c2c66affSColin Finck 
impl_from_IDxDiagProvider(IDxDiagProvider * iface)112c2c66affSColin Finck static inline IDxDiagProviderImpl *impl_from_IDxDiagProvider(IDxDiagProvider *iface)
113c2c66affSColin Finck {
114c2c66affSColin Finck      return CONTAINING_RECORD(iface, IDxDiagProviderImpl, IDxDiagProvider_iface);
115c2c66affSColin Finck }
116c2c66affSColin Finck 
117c2c66affSColin Finck /* IDxDiagProvider IUnknown parts follow: */
IDxDiagProviderImpl_QueryInterface(IDxDiagProvider * iface,REFIID riid,void ** ppobj)118c2c66affSColin Finck static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(IDxDiagProvider *iface, REFIID riid,
119c2c66affSColin Finck         void **ppobj)
120c2c66affSColin Finck {
121c2c66affSColin Finck     IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
122c2c66affSColin Finck 
123c2c66affSColin Finck     if (!ppobj) return E_INVALIDARG;
124c2c66affSColin Finck 
125c2c66affSColin Finck     if (IsEqualGUID(riid, &IID_IUnknown)
126c2c66affSColin Finck         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
127c2c66affSColin Finck         IUnknown_AddRef(iface);
128c2c66affSColin Finck         *ppobj = This;
129c2c66affSColin Finck         return S_OK;
130c2c66affSColin Finck     }
131c2c66affSColin Finck 
132c2c66affSColin Finck     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
133c2c66affSColin Finck     *ppobj = NULL;
134c2c66affSColin Finck     return E_NOINTERFACE;
135c2c66affSColin Finck }
136c2c66affSColin Finck 
IDxDiagProviderImpl_AddRef(IDxDiagProvider * iface)137c2c66affSColin Finck static ULONG WINAPI IDxDiagProviderImpl_AddRef(IDxDiagProvider *iface)
138c2c66affSColin Finck {
139c2c66affSColin Finck     IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
140c2c66affSColin Finck     ULONG refCount = InterlockedIncrement(&This->ref);
141c2c66affSColin Finck 
142c2c66affSColin Finck     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
143c2c66affSColin Finck 
144c2c66affSColin Finck     DXDIAGN_LockModule();
145c2c66affSColin Finck 
146c2c66affSColin Finck     return refCount;
147c2c66affSColin Finck }
148c2c66affSColin Finck 
IDxDiagProviderImpl_Release(IDxDiagProvider * iface)149c2c66affSColin Finck static ULONG WINAPI IDxDiagProviderImpl_Release(IDxDiagProvider *iface)
150c2c66affSColin Finck {
151c2c66affSColin Finck     IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
152c2c66affSColin Finck     ULONG refCount = InterlockedDecrement(&This->ref);
153c2c66affSColin Finck 
154c2c66affSColin Finck     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
155c2c66affSColin Finck 
156c2c66affSColin Finck     if (!refCount) {
157c2c66affSColin Finck         free_information_tree(This->info_root);
158c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, This);
159c2c66affSColin Finck     }
160c2c66affSColin Finck 
161c2c66affSColin Finck     DXDIAGN_UnlockModule();
162c2c66affSColin Finck 
163c2c66affSColin Finck     return refCount;
164c2c66affSColin Finck }
165c2c66affSColin Finck 
166c2c66affSColin Finck /* IDxDiagProvider Interface follow: */
IDxDiagProviderImpl_Initialize(IDxDiagProvider * iface,DXDIAG_INIT_PARAMS * pParams)167c2c66affSColin Finck static HRESULT WINAPI IDxDiagProviderImpl_Initialize(IDxDiagProvider *iface,
168c2c66affSColin Finck         DXDIAG_INIT_PARAMS *pParams)
169c2c66affSColin Finck {
170c2c66affSColin Finck     IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
171c2c66affSColin Finck     HRESULT hr;
172c2c66affSColin Finck 
173c2c66affSColin Finck     TRACE("(%p,%p)\n", iface, pParams);
174c2c66affSColin Finck 
175c2c66affSColin Finck     if (NULL == pParams) {
176c2c66affSColin Finck       return E_POINTER;
177c2c66affSColin Finck     }
178c2c66affSColin Finck     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS) ||
179c2c66affSColin Finck         pParams->dwDxDiagHeaderVersion != DXDIAG_DX9_SDK_VERSION) {
180c2c66affSColin Finck       return E_INVALIDARG;
181c2c66affSColin Finck     }
182c2c66affSColin Finck 
183c2c66affSColin Finck     if (!This->info_root)
184c2c66affSColin Finck     {
185c2c66affSColin Finck         hr = build_information_tree(&This->info_root);
186c2c66affSColin Finck         if (FAILED(hr))
187c2c66affSColin Finck             return hr;
188c2c66affSColin Finck     }
189c2c66affSColin Finck 
190c2c66affSColin Finck     This->init = TRUE;
191c2c66affSColin Finck     memcpy(&This->params, pParams, pParams->dwSize);
192c2c66affSColin Finck     return S_OK;
193c2c66affSColin Finck }
194c2c66affSColin Finck 
IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider * iface,IDxDiagContainer ** ppInstance)195c2c66affSColin Finck static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(IDxDiagProvider *iface,
196c2c66affSColin Finck         IDxDiagContainer **ppInstance)
197c2c66affSColin Finck {
198c2c66affSColin Finck   IDxDiagProviderImpl *This = impl_from_IDxDiagProvider(iface);
199c2c66affSColin Finck 
200c2c66affSColin Finck   TRACE("(%p,%p)\n", iface, ppInstance);
201c2c66affSColin Finck 
202c2c66affSColin Finck   if (FALSE == This->init) {
203c2c66affSColin Finck     return CO_E_NOTINITIALIZED;
204c2c66affSColin Finck   }
205c2c66affSColin Finck 
206c2c66affSColin Finck   return DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, This->info_root,
207c2c66affSColin Finck           &This->IDxDiagProvider_iface, (void **)ppInstance);
208c2c66affSColin Finck }
209c2c66affSColin Finck 
210c2c66affSColin Finck static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
211c2c66affSColin Finck {
212c2c66affSColin Finck     IDxDiagProviderImpl_QueryInterface,
213c2c66affSColin Finck     IDxDiagProviderImpl_AddRef,
214c2c66affSColin Finck     IDxDiagProviderImpl_Release,
215c2c66affSColin Finck     IDxDiagProviderImpl_Initialize,
216c2c66affSColin Finck     IDxDiagProviderImpl_GetRootContainer
217c2c66affSColin Finck };
218c2c66affSColin Finck 
DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface,LPUNKNOWN punkOuter,REFIID riid,LPVOID * ppobj)219c2c66affSColin Finck HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
220c2c66affSColin Finck   IDxDiagProviderImpl* provider;
221c2c66affSColin Finck 
222c2c66affSColin Finck   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
223c2c66affSColin Finck 
224c2c66affSColin Finck   *ppobj = NULL;
225c2c66affSColin Finck   if (punkOuter) return CLASS_E_NOAGGREGATION;
226c2c66affSColin Finck 
227c2c66affSColin Finck   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
228c2c66affSColin Finck   if (NULL == provider) return E_OUTOFMEMORY;
229c2c66affSColin Finck   provider->IDxDiagProvider_iface.lpVtbl = &DxDiagProvider_Vtbl;
230c2c66affSColin Finck   provider->ref = 0; /* will be inited with QueryInterface */
231c2c66affSColin Finck   return IDxDiagProviderImpl_QueryInterface(&provider->IDxDiagProvider_iface, riid, ppobj);
232c2c66affSColin Finck }
233c2c66affSColin Finck 
free_property_information(IDxDiagContainerImpl_Property * prop)234c2c66affSColin Finck static void free_property_information(IDxDiagContainerImpl_Property *prop)
235c2c66affSColin Finck {
236c2c66affSColin Finck     VariantClear(&prop->vProp);
237c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, prop->propName);
238c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, prop);
239c2c66affSColin Finck }
240c2c66affSColin Finck 
free_information_tree(IDxDiagContainerImpl_Container * node)241c2c66affSColin Finck static void free_information_tree(IDxDiagContainerImpl_Container *node)
242c2c66affSColin Finck {
243c2c66affSColin Finck     IDxDiagContainerImpl_Container *ptr, *cursor2;
244c2c66affSColin Finck 
245c2c66affSColin Finck     if (!node)
246c2c66affSColin Finck         return;
247c2c66affSColin Finck 
248c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, node->contName);
249c2c66affSColin Finck 
250c2c66affSColin Finck     LIST_FOR_EACH_ENTRY_SAFE(ptr, cursor2, &node->subContainers, IDxDiagContainerImpl_Container, entry)
251c2c66affSColin Finck     {
252c2c66affSColin Finck         IDxDiagContainerImpl_Property *prop, *prop_cursor2;
253c2c66affSColin Finck 
254c2c66affSColin Finck         LIST_FOR_EACH_ENTRY_SAFE(prop, prop_cursor2, &ptr->properties, IDxDiagContainerImpl_Property, entry)
255c2c66affSColin Finck         {
256c2c66affSColin Finck             list_remove(&prop->entry);
257c2c66affSColin Finck             free_property_information(prop);
258c2c66affSColin Finck         }
259c2c66affSColin Finck 
260c2c66affSColin Finck         list_remove(&ptr->entry);
261c2c66affSColin Finck         free_information_tree(ptr);
262c2c66affSColin Finck     }
263c2c66affSColin Finck 
264c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, node);
265c2c66affSColin Finck }
266c2c66affSColin Finck 
allocate_information_node(const WCHAR * name)267c2c66affSColin Finck static IDxDiagContainerImpl_Container *allocate_information_node(const WCHAR *name)
268c2c66affSColin Finck {
269c2c66affSColin Finck     IDxDiagContainerImpl_Container *ret;
270c2c66affSColin Finck 
271c2c66affSColin Finck     ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
272c2c66affSColin Finck     if (!ret)
273c2c66affSColin Finck         return NULL;
274c2c66affSColin Finck 
275c2c66affSColin Finck     if (name)
276c2c66affSColin Finck     {
277*d6c879a0SAmine Khaldi         ret->contName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(*name));
278c2c66affSColin Finck         if (!ret->contName)
279c2c66affSColin Finck         {
280c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, ret);
281c2c66affSColin Finck             return NULL;
282c2c66affSColin Finck         }
283*d6c879a0SAmine Khaldi         lstrcpyW(ret->contName, name);
284c2c66affSColin Finck     }
285c2c66affSColin Finck 
286c2c66affSColin Finck     list_init(&ret->subContainers);
287c2c66affSColin Finck     list_init(&ret->properties);
288c2c66affSColin Finck 
289c2c66affSColin Finck     return ret;
290c2c66affSColin Finck }
291c2c66affSColin Finck 
allocate_property_information(const WCHAR * name)292c2c66affSColin Finck static IDxDiagContainerImpl_Property *allocate_property_information(const WCHAR *name)
293c2c66affSColin Finck {
294c2c66affSColin Finck     IDxDiagContainerImpl_Property *ret;
295c2c66affSColin Finck 
296c2c66affSColin Finck     ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
297c2c66affSColin Finck     if (!ret)
298c2c66affSColin Finck         return NULL;
299c2c66affSColin Finck 
300*d6c879a0SAmine Khaldi     ret->propName = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(name) + 1) * sizeof(*name));
301c2c66affSColin Finck     if (!ret->propName)
302c2c66affSColin Finck     {
303c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, ret);
304c2c66affSColin Finck         return NULL;
305c2c66affSColin Finck     }
306*d6c879a0SAmine Khaldi     lstrcpyW(ret->propName, name);
307c2c66affSColin Finck 
308c2c66affSColin Finck     return ret;
309c2c66affSColin Finck }
310c2c66affSColin Finck 
add_subcontainer(IDxDiagContainerImpl_Container * node,IDxDiagContainerImpl_Container * subCont)311c2c66affSColin Finck static inline void add_subcontainer(IDxDiagContainerImpl_Container *node, IDxDiagContainerImpl_Container *subCont)
312c2c66affSColin Finck {
313c2c66affSColin Finck     list_add_tail(&node->subContainers, &subCont->entry);
314c2c66affSColin Finck     ++node->nSubContainers;
315c2c66affSColin Finck }
316c2c66affSColin Finck 
add_bstr_property(IDxDiagContainerImpl_Container * node,const WCHAR * propName,const WCHAR * str)317c2c66affSColin Finck static inline HRESULT add_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, const WCHAR *str)
318c2c66affSColin Finck {
319c2c66affSColin Finck     IDxDiagContainerImpl_Property *prop;
320c2c66affSColin Finck     BSTR bstr;
321c2c66affSColin Finck 
322c2c66affSColin Finck     prop = allocate_property_information(propName);
323c2c66affSColin Finck     if (!prop)
324c2c66affSColin Finck         return E_OUTOFMEMORY;
325c2c66affSColin Finck 
326c2c66affSColin Finck     bstr = SysAllocString(str);
327c2c66affSColin Finck     if (!bstr)
328c2c66affSColin Finck     {
329c2c66affSColin Finck         free_property_information(prop);
330c2c66affSColin Finck         return E_OUTOFMEMORY;
331c2c66affSColin Finck     }
332c2c66affSColin Finck 
333c2c66affSColin Finck     V_VT(&prop->vProp) = VT_BSTR;
334c2c66affSColin Finck     V_BSTR(&prop->vProp) = bstr;
335c2c66affSColin Finck 
336c2c66affSColin Finck     list_add_tail(&node->properties, &prop->entry);
337c2c66affSColin Finck     ++node->nProperties;
338c2c66affSColin Finck 
339c2c66affSColin Finck     return S_OK;
340c2c66affSColin Finck }
341c2c66affSColin Finck 
add_ui4_property(IDxDiagContainerImpl_Container * node,const WCHAR * propName,DWORD data)342c2c66affSColin Finck static inline HRESULT add_ui4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, DWORD data)
343c2c66affSColin Finck {
344c2c66affSColin Finck     IDxDiagContainerImpl_Property *prop;
345c2c66affSColin Finck 
346c2c66affSColin Finck     prop = allocate_property_information(propName);
347c2c66affSColin Finck     if (!prop)
348c2c66affSColin Finck         return E_OUTOFMEMORY;
349c2c66affSColin Finck 
350c2c66affSColin Finck     V_VT(&prop->vProp) = VT_UI4;
351c2c66affSColin Finck     V_UI4(&prop->vProp) = data;
352c2c66affSColin Finck 
353c2c66affSColin Finck     list_add_tail(&node->properties, &prop->entry);
354c2c66affSColin Finck     ++node->nProperties;
355c2c66affSColin Finck 
356c2c66affSColin Finck     return S_OK;
357c2c66affSColin Finck }
358c2c66affSColin Finck 
add_i4_property(IDxDiagContainerImpl_Container * node,const WCHAR * propName,LONG data)359afc3201bSAmine Khaldi static inline HRESULT add_i4_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, LONG data)
360afc3201bSAmine Khaldi {
361afc3201bSAmine Khaldi     IDxDiagContainerImpl_Property *prop;
362afc3201bSAmine Khaldi 
363afc3201bSAmine Khaldi     prop = allocate_property_information(propName);
364afc3201bSAmine Khaldi     if (!prop)
365afc3201bSAmine Khaldi         return E_OUTOFMEMORY;
366afc3201bSAmine Khaldi 
367afc3201bSAmine Khaldi     V_VT(&prop->vProp) = VT_I4;
368afc3201bSAmine Khaldi     V_I4(&prop->vProp) = data;
369afc3201bSAmine Khaldi 
370afc3201bSAmine Khaldi     list_add_tail(&node->properties, &prop->entry);
371afc3201bSAmine Khaldi     ++node->nProperties;
372afc3201bSAmine Khaldi 
373afc3201bSAmine Khaldi     return S_OK;
374afc3201bSAmine Khaldi }
375afc3201bSAmine Khaldi 
add_bool_property(IDxDiagContainerImpl_Container * node,const WCHAR * propName,BOOL data)376c2c66affSColin Finck static inline HRESULT add_bool_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, BOOL data)
377c2c66affSColin Finck {
378c2c66affSColin Finck     IDxDiagContainerImpl_Property *prop;
379c2c66affSColin Finck 
380c2c66affSColin Finck     prop = allocate_property_information(propName);
381c2c66affSColin Finck     if (!prop)
382c2c66affSColin Finck         return E_OUTOFMEMORY;
383c2c66affSColin Finck 
384c2c66affSColin Finck     V_VT(&prop->vProp) = VT_BOOL;
385c2c66affSColin Finck     V_BOOL(&prop->vProp) = data ? VARIANT_TRUE : VARIANT_FALSE;
386c2c66affSColin Finck 
387c2c66affSColin Finck     list_add_tail(&node->properties, &prop->entry);
388c2c66affSColin Finck     ++node->nProperties;
389c2c66affSColin Finck 
390c2c66affSColin Finck     return S_OK;
391c2c66affSColin Finck }
392c2c66affSColin Finck 
add_ull_as_bstr_property(IDxDiagContainerImpl_Container * node,const WCHAR * propName,ULONGLONG data)393c2c66affSColin Finck static inline HRESULT add_ull_as_bstr_property(IDxDiagContainerImpl_Container *node, const WCHAR *propName, ULONGLONG data )
394c2c66affSColin Finck {
395c2c66affSColin Finck     IDxDiagContainerImpl_Property *prop;
396c2c66affSColin Finck     HRESULT hr;
397c2c66affSColin Finck 
398c2c66affSColin Finck     prop = allocate_property_information(propName);
399c2c66affSColin Finck     if (!prop)
400c2c66affSColin Finck         return E_OUTOFMEMORY;
401c2c66affSColin Finck 
402c2c66affSColin Finck     V_VT(&prop->vProp) = VT_UI8;
403c2c66affSColin Finck     V_UI8(&prop->vProp) = data;
404c2c66affSColin Finck 
405c2c66affSColin Finck     hr = VariantChangeType(&prop->vProp, &prop->vProp, 0, VT_BSTR);
406c2c66affSColin Finck     if (FAILED(hr))
407c2c66affSColin Finck     {
408c2c66affSColin Finck         free_property_information(prop);
409c2c66affSColin Finck         return hr;
410c2c66affSColin Finck     }
411c2c66affSColin Finck 
412c2c66affSColin Finck     list_add_tail(&node->properties, &prop->entry);
413c2c66affSColin Finck     ++node->nProperties;
414c2c66affSColin Finck 
415c2c66affSColin Finck     return S_OK;
416c2c66affSColin Finck }
417c2c66affSColin Finck 
418c2c66affSColin Finck /* Copied from programs/taskkill/taskkill.c. */
enumerate_processes(DWORD * list_count)419c2c66affSColin Finck static DWORD *enumerate_processes(DWORD *list_count)
420c2c66affSColin Finck {
421c2c66affSColin Finck     DWORD *pid_list, alloc_bytes = 1024 * sizeof(*pid_list), needed_bytes;
422c2c66affSColin Finck 
423c2c66affSColin Finck     pid_list = HeapAlloc(GetProcessHeap(), 0, alloc_bytes);
424c2c66affSColin Finck     if (!pid_list)
425c2c66affSColin Finck         return NULL;
426c2c66affSColin Finck 
427c2c66affSColin Finck     for (;;)
428c2c66affSColin Finck     {
429c2c66affSColin Finck         DWORD *realloc_list;
430c2c66affSColin Finck 
431c2c66affSColin Finck         if (!EnumProcesses(pid_list, alloc_bytes, &needed_bytes))
432c2c66affSColin Finck         {
433c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pid_list);
434c2c66affSColin Finck             return NULL;
435c2c66affSColin Finck         }
436c2c66affSColin Finck 
437c2c66affSColin Finck         /* EnumProcesses can't signal an insufficient buffer condition, so the
438c2c66affSColin Finck          * only way to possibly determine whether a larger buffer is required
439c2c66affSColin Finck          * is to see whether the written number of bytes is the same as the
440c2c66affSColin Finck          * buffer size. If so, the buffer will be reallocated to twice the
441c2c66affSColin Finck          * size. */
442c2c66affSColin Finck         if (alloc_bytes != needed_bytes)
443c2c66affSColin Finck             break;
444c2c66affSColin Finck 
445c2c66affSColin Finck         alloc_bytes *= 2;
446c2c66affSColin Finck         realloc_list = HeapReAlloc(GetProcessHeap(), 0, pid_list, alloc_bytes);
447c2c66affSColin Finck         if (!realloc_list)
448c2c66affSColin Finck         {
449c2c66affSColin Finck             HeapFree(GetProcessHeap(), 0, pid_list);
450c2c66affSColin Finck             return NULL;
451c2c66affSColin Finck         }
452c2c66affSColin Finck         pid_list = realloc_list;
453c2c66affSColin Finck     }
454c2c66affSColin Finck 
455c2c66affSColin Finck     *list_count = needed_bytes / sizeof(*pid_list);
456c2c66affSColin Finck     return pid_list;
457c2c66affSColin Finck }
458c2c66affSColin Finck 
459c2c66affSColin Finck /* Copied from programs/taskkill/taskkill.c. */
get_process_name_from_pid(DWORD pid,WCHAR * buf,DWORD chars)460c2c66affSColin Finck static BOOL get_process_name_from_pid(DWORD pid, WCHAR *buf, DWORD chars)
461c2c66affSColin Finck {
462c2c66affSColin Finck     HANDLE process;
463c2c66affSColin Finck     HMODULE module;
464c2c66affSColin Finck     DWORD required_size;
465c2c66affSColin Finck 
466c2c66affSColin Finck     process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
467c2c66affSColin Finck     if (!process)
468c2c66affSColin Finck         return FALSE;
469c2c66affSColin Finck 
470c2c66affSColin Finck     if (!EnumProcessModules(process, &module, sizeof(module), &required_size))
471c2c66affSColin Finck     {
472c2c66affSColin Finck         CloseHandle(process);
473c2c66affSColin Finck         return FALSE;
474c2c66affSColin Finck     }
475c2c66affSColin Finck 
476c2c66affSColin Finck     if (!GetModuleBaseNameW(process, module, buf, chars))
477c2c66affSColin Finck     {
478c2c66affSColin Finck         CloseHandle(process);
479c2c66affSColin Finck         return FALSE;
480c2c66affSColin Finck     }
481c2c66affSColin Finck 
482c2c66affSColin Finck     CloseHandle(process);
483c2c66affSColin Finck     return TRUE;
484c2c66affSColin Finck }
485c2c66affSColin Finck 
486c2c66affSColin Finck /* dxdiagn's detection scheme is simply to look for a process called conf.exe. */
is_netmeeting_running(void)487c2c66affSColin Finck static BOOL is_netmeeting_running(void)
488c2c66affSColin Finck {
489c2c66affSColin Finck     static const WCHAR conf_exe[] = {'c','o','n','f','.','e','x','e',0};
490c2c66affSColin Finck 
491c2c66affSColin Finck     DWORD list_count;
492c2c66affSColin Finck     DWORD *pid_list = enumerate_processes(&list_count);
493c2c66affSColin Finck 
494c2c66affSColin Finck     if (pid_list)
495c2c66affSColin Finck     {
496c2c66affSColin Finck         DWORD i;
497c2c66affSColin Finck         WCHAR process_name[MAX_PATH];
498c2c66affSColin Finck 
499c2c66affSColin Finck         for (i = 0; i < list_count; i++)
500c2c66affSColin Finck         {
501*d6c879a0SAmine Khaldi             if (get_process_name_from_pid(pid_list[i], process_name, ARRAY_SIZE(process_name)) &&
502c2c66affSColin Finck                 !lstrcmpW(conf_exe, process_name))
503c2c66affSColin Finck             {
504c2c66affSColin Finck                 HeapFree(GetProcessHeap(), 0, pid_list);
505c2c66affSColin Finck                 return TRUE;
506c2c66affSColin Finck             }
507c2c66affSColin Finck         }
508c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pid_list);
509c2c66affSColin Finck     }
510c2c66affSColin Finck 
511c2c66affSColin Finck     return FALSE;
512c2c66affSColin Finck }
513c2c66affSColin Finck 
fill_language_information(IDxDiagContainerImpl_Container * node)514c2c66affSColin Finck static HRESULT fill_language_information(IDxDiagContainerImpl_Container *node)
515c2c66affSColin Finck {
516c2c66affSColin Finck     static const WCHAR regional_setting_engW[] = {'R','e','g','i','o','n','a','l',' ','S','e','t','t','i','n','g',0};
517c2c66affSColin Finck     static const WCHAR languages_fmtW[] = {'%','s',' ','(','%','s',':',' ','%','s',')',0};
518c2c66affSColin Finck     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};
519c2c66affSColin Finck     static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
520c2c66affSColin Finck 
521c2c66affSColin Finck     WCHAR system_lang[80], regional_setting[100], user_lang[80], language_str[300];
522c2c66affSColin Finck     HRESULT hr;
523c2c66affSColin Finck 
524c2c66affSColin Finck     /* szLanguagesLocalized */
525*d6c879a0SAmine Khaldi     GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SNATIVELANGNAME, system_lang, ARRAY_SIZE(system_lang));
526*d6c879a0SAmine Khaldi     LoadStringW(dxdiagn_instance, IDS_REGIONAL_SETTING, regional_setting, ARRAY_SIZE(regional_setting));
527*d6c879a0SAmine Khaldi     GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SNATIVELANGNAME, user_lang, ARRAY_SIZE(user_lang));
528c2c66affSColin Finck 
529*d6c879a0SAmine Khaldi     swprintf(language_str, languages_fmtW, system_lang, regional_setting,
530*d6c879a0SAmine Khaldi               user_lang);
531c2c66affSColin Finck 
532c2c66affSColin Finck     hr = add_bstr_property(node, szLanguagesLocalized, language_str);
533c2c66affSColin Finck     if (FAILED(hr))
534c2c66affSColin Finck         return hr;
535c2c66affSColin Finck 
536c2c66affSColin Finck     /* szLanguagesEnglish */
537*d6c879a0SAmine Khaldi     GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SENGLANGUAGE, system_lang, ARRAY_SIZE(system_lang));
538*d6c879a0SAmine Khaldi     GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SENGLANGUAGE, user_lang, ARRAY_SIZE(user_lang));
539c2c66affSColin Finck 
540*d6c879a0SAmine Khaldi     swprintf(language_str, languages_fmtW, system_lang,
541*d6c879a0SAmine Khaldi               regional_setting_engW, user_lang);
542c2c66affSColin Finck 
543c2c66affSColin Finck     hr = add_bstr_property(node, szLanguagesEnglish, language_str);
544c2c66affSColin Finck     if (FAILED(hr))
545c2c66affSColin Finck         return hr;
546c2c66affSColin Finck 
547c2c66affSColin Finck     return S_OK;
548c2c66affSColin Finck }
549c2c66affSColin Finck 
fill_datetime_information(IDxDiagContainerImpl_Container * node)550c2c66affSColin Finck static HRESULT fill_datetime_information(IDxDiagContainerImpl_Container *node)
551c2c66affSColin Finck {
552c2c66affSColin Finck     static const WCHAR date_fmtW[] = {'M','\'','/','\'','d','\'','/','\'','y','y','y','y',0};
553c2c66affSColin Finck     static const WCHAR time_fmtW[] = {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
554c2c66affSColin Finck     static const WCHAR datetime_fmtW[] = {'%','s',',',' ','%','s',0};
555c2c66affSColin Finck     static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
556c2c66affSColin Finck     static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
557c2c66affSColin Finck 
558c2c66affSColin Finck     SYSTEMTIME curtime;
559c2c66affSColin Finck     WCHAR date_str[80], time_str[80], datetime_str[200];
560c2c66affSColin Finck     HRESULT hr;
561c2c66affSColin Finck 
562c2c66affSColin Finck     GetLocalTime(&curtime);
563c2c66affSColin Finck 
564*d6c879a0SAmine Khaldi     GetTimeFormatW(LOCALE_NEUTRAL, 0, &curtime, time_fmtW, time_str, ARRAY_SIZE(time_str));
565c2c66affSColin Finck 
566c2c66affSColin Finck     /* szTimeLocalized */
567*d6c879a0SAmine Khaldi     GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &curtime, NULL, date_str, ARRAY_SIZE(date_str));
568c2c66affSColin Finck 
569*d6c879a0SAmine Khaldi     swprintf(datetime_str, datetime_fmtW, date_str, time_str);
570c2c66affSColin Finck 
571c2c66affSColin Finck     hr = add_bstr_property(node, szTimeLocalized, datetime_str);
572c2c66affSColin Finck     if (FAILED(hr))
573c2c66affSColin Finck         return hr;
574c2c66affSColin Finck 
575c2c66affSColin Finck     /* szTimeEnglish */
576*d6c879a0SAmine Khaldi     GetDateFormatW(LOCALE_NEUTRAL, 0, &curtime, date_fmtW, date_str, ARRAY_SIZE(date_str));
577c2c66affSColin Finck 
578*d6c879a0SAmine Khaldi     swprintf(datetime_str, datetime_fmtW, date_str, time_str);
579c2c66affSColin Finck 
580c2c66affSColin Finck     hr = add_bstr_property(node, szTimeEnglish, datetime_str);
581c2c66affSColin Finck     if (FAILED(hr))
582c2c66affSColin Finck         return hr;
583c2c66affSColin Finck 
584c2c66affSColin Finck     return S_OK;
585c2c66affSColin Finck }
586c2c66affSColin Finck 
fill_os_string_information(IDxDiagContainerImpl_Container * node,OSVERSIONINFOW * info)587c2c66affSColin Finck static HRESULT fill_os_string_information(IDxDiagContainerImpl_Container *node, OSVERSIONINFOW *info)
588c2c66affSColin Finck {
589c2c66affSColin Finck     static const WCHAR winxpW[] = {'W','i','n','d','o','w','s',' ','X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
590c2c66affSColin Finck     static const WCHAR szOSLocalized[] = {'s','z','O','S','L','o','c','a','l','i','z','e','d',0};
591c2c66affSColin Finck     static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
592c2c66affSColin Finck     static const WCHAR szOSExLongLocalized[] = {'s','z','O','S','E','x','L','o','n','g','L','o','c','a','l','i','z','e','d',0};
593c2c66affSColin Finck     static const WCHAR szOSEnglish[] = {'s','z','O','S','E','n','g','l','i','s','h',0};
594c2c66affSColin Finck     static const WCHAR szOSExEnglish[] = {'s','z','O','S','E','x','E','n','g','l','i','s','h',0};
595c2c66affSColin Finck     static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
596c2c66affSColin Finck 
597c2c66affSColin Finck     static const WCHAR *prop_list[] = {szOSLocalized, szOSExLocalized, szOSExLongLocalized,
598c2c66affSColin Finck                                        szOSEnglish, szOSExEnglish, szOSExLongEnglish};
599c2c66affSColin Finck 
600c2c66affSColin Finck     size_t i;
601c2c66affSColin Finck     HRESULT hr;
602c2c66affSColin Finck 
603c2c66affSColin Finck     /* FIXME: OS detection should be performed, and localized OS strings
604c2c66affSColin Finck      * should contain translated versions of the "build" phrase. */
605*d6c879a0SAmine Khaldi     for (i = 0; i < ARRAY_SIZE(prop_list); i++)
606c2c66affSColin Finck     {
607c2c66affSColin Finck         hr = add_bstr_property(node, prop_list[i], winxpW);
608c2c66affSColin Finck         if (FAILED(hr))
609c2c66affSColin Finck             return hr;
610c2c66affSColin Finck     }
611c2c66affSColin Finck 
612c2c66affSColin Finck     return S_OK;
613c2c66affSColin Finck }
614c2c66affSColin Finck 
fill_processor_information(IDxDiagContainerImpl_Container * node)615c2c66affSColin Finck static HRESULT fill_processor_information(IDxDiagContainerImpl_Container *node)
616c2c66affSColin Finck {
617c2c66affSColin Finck     static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
618c2c66affSColin Finck 
619c2c66affSColin Finck     static const WCHAR cimv2W[] = {'\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
620c2c66affSColin Finck     static const WCHAR proc_classW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
621c2c66affSColin Finck     static const WCHAR nameW[] = {'N','a','m','e',0};
622c2c66affSColin Finck     static const WCHAR max_clock_speedW[] = {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
623c2c66affSColin Finck     static const WCHAR cpu_noW[] = {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
624c2c66affSColin Finck 
625c2c66affSColin Finck     static const WCHAR processor_fmtW[] = {'%','s','(','%','d',' ','C','P','U','s',')',',',' ','~','%','d','M','H','z',0};
626c2c66affSColin Finck 
627c2c66affSColin Finck     IWbemLocator *wbem_locator;
628c2c66affSColin Finck     IWbemServices *wbem_service;
629c2c66affSColin Finck     IWbemClassObject *wbem_class;
630c2c66affSColin Finck     IEnumWbemClassObject *wbem_enum;
631c2c66affSColin Finck     VARIANT cpu_name, cpu_no, clock_speed;
632c2c66affSColin Finck     WCHAR print_buf[200];
633c2c66affSColin Finck     BSTR bstr;
634c2c66affSColin Finck     ULONG no;
635c2c66affSColin Finck     HRESULT hr;
636c2c66affSColin Finck 
637c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (void**)&wbem_locator);
638c2c66affSColin Finck     if(FAILED(hr))
639c2c66affSColin Finck         return hr;
640c2c66affSColin Finck 
641c2c66affSColin Finck     bstr = SysAllocString(cimv2W);
642c2c66affSColin Finck     if(!bstr) {
643c2c66affSColin Finck         IWbemLocator_Release(wbem_locator);
644c2c66affSColin Finck         return E_OUTOFMEMORY;
645c2c66affSColin Finck     }
646c2c66affSColin Finck     hr = IWbemLocator_ConnectServer(wbem_locator, bstr, NULL, NULL, NULL, 0, NULL, NULL, &wbem_service);
647c2c66affSColin Finck     IWbemLocator_Release(wbem_locator);
648c2c66affSColin Finck     SysFreeString(bstr);
649c2c66affSColin Finck     if(FAILED(hr))
650c2c66affSColin Finck         return hr;
651c2c66affSColin Finck 
652c2c66affSColin Finck     bstr = SysAllocString(proc_classW);
653c2c66affSColin Finck     if(!bstr) {
654c2c66affSColin Finck         IWbemServices_Release(wbem_service);
655c2c66affSColin Finck         return E_OUTOFMEMORY;
656c2c66affSColin Finck     }
657c2c66affSColin Finck     hr = IWbemServices_CreateInstanceEnum(wbem_service, bstr, WBEM_FLAG_SYSTEM_ONLY, NULL, &wbem_enum);
658c2c66affSColin Finck     IWbemServices_Release(wbem_service);
659c2c66affSColin Finck     SysFreeString(bstr);
660c2c66affSColin Finck     if(FAILED(hr))
661c2c66affSColin Finck         return hr;
662c2c66affSColin Finck 
663c2c66affSColin Finck     hr = IEnumWbemClassObject_Next(wbem_enum, 1000, 1, &wbem_class, &no);
664c2c66affSColin Finck     IEnumWbemClassObject_Release(wbem_enum);
665c2c66affSColin Finck     if(FAILED(hr))
666c2c66affSColin Finck         return hr;
667c2c66affSColin Finck 
668c2c66affSColin Finck     hr = IWbemClassObject_Get(wbem_class, cpu_noW, 0, &cpu_no, NULL, NULL);
669c2c66affSColin Finck     if(FAILED(hr)) {
670c2c66affSColin Finck         IWbemClassObject_Release(wbem_class);
671c2c66affSColin Finck         return hr;
672c2c66affSColin Finck     }
673c2c66affSColin Finck     hr = IWbemClassObject_Get(wbem_class, max_clock_speedW, 0, &clock_speed, NULL, NULL);
674c2c66affSColin Finck     if(FAILED(hr)) {
675c2c66affSColin Finck         IWbemClassObject_Release(wbem_class);
676c2c66affSColin Finck         return hr;
677c2c66affSColin Finck     }
678c2c66affSColin Finck     hr = IWbemClassObject_Get(wbem_class, nameW, 0, &cpu_name, NULL, NULL);
679c2c66affSColin Finck     IWbemClassObject_Release(wbem_class);
680c2c66affSColin Finck     if(FAILED(hr))
681c2c66affSColin Finck         return hr;
682c2c66affSColin Finck 
683*d6c879a0SAmine Khaldi     swprintf(print_buf, processor_fmtW,
684*d6c879a0SAmine Khaldi              V_BSTR(&cpu_name), V_I4(&cpu_no), V_I4(&clock_speed));
685c2c66affSColin Finck     VariantClear(&cpu_name);
686c2c66affSColin Finck     VariantClear(&cpu_no);
687c2c66affSColin Finck     VariantClear(&clock_speed);
688c2c66affSColin Finck 
689c2c66affSColin Finck     return add_bstr_property(node, szProcessorEnglish, print_buf);
690c2c66affSColin Finck }
691c2c66affSColin Finck 
build_systeminfo_tree(IDxDiagContainerImpl_Container * node)692c2c66affSColin Finck static HRESULT build_systeminfo_tree(IDxDiagContainerImpl_Container *node)
693c2c66affSColin Finck {
694c2c66affSColin Finck     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};
695c2c66affSColin Finck     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};
696c2c66affSColin Finck     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};
697c2c66affSColin Finck     static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
698c2c66affSColin Finck     static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
699c2c66affSColin Finck     static const WCHAR bNECPC98[] = {'b','N','E','C','P','C','9','8',0};
700c2c66affSColin Finck     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};
701c2c66affSColin Finck     static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
702c2c66affSColin Finck     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};
703c2c66affSColin Finck     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};
704c2c66affSColin Finck     static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
705c2c66affSColin Finck     static const WCHAR ullUsedPageFile[]   = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
706c2c66affSColin Finck     static const WCHAR ullAvailPageFile[]  = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
707c2c66affSColin Finck     static const WCHAR bNetMeetingRunning[] = {'b','N','e','t','M','e','e','t','i','n','g','R','u','n','n','i','n','g',0};
708c2c66affSColin Finck     static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
709c2c66affSColin Finck     static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
710c2c66affSColin Finck     static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
711c2c66affSColin Finck     static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
712c2c66affSColin Finck     static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
713c2c66affSColin Finck     static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
714c2c66affSColin Finck     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};
715c2c66affSColin Finck     static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
716c2c66affSColin Finck     static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
717c2c66affSColin Finck     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};
718c2c66affSColin Finck     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};
719c2c66affSColin Finck     static const WCHAR szSystemManufacturerEnglish[] = {'s','z','S','y','s','t','e','m','M','a','n','u','f','a','c','t','u','r','e','r','E','n','g','l','i','s','h',0};
720c2c66affSColin Finck     static const WCHAR szSystemModelEnglish[] = {'s','z','S','y','s','t','e','m','M','o','d','e','l','E','n','g','l','i','s','h',0};
721c2c66affSColin Finck     static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
722c2c66affSColin Finck     static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
723c2c66affSColin Finck     static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
724c2c66affSColin Finck 
725c2c66affSColin Finck     static const WCHAR notpresentW[] = {'N','o','t',' ','p','r','e','s','e','n','t',0};
726c2c66affSColin Finck 
727c2c66affSColin Finck     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};
728c2c66affSColin Finck     static const WCHAR physmem_fmtW[] = {'%','u','M','B',' ','R','A','M',0};
729c2c66affSColin Finck 
730c2c66affSColin Finck     HRESULT hr;
731c2c66affSColin Finck     MEMORYSTATUSEX msex;
732c2c66affSColin Finck     OSVERSIONINFOW info;
733c2c66affSColin Finck     DWORD count, usedpage_mb, availpage_mb;
734c2c66affSColin Finck     WCHAR buffer[MAX_PATH], computer_name[MAX_COMPUTERNAME_LENGTH + 1], print_buf[200], localized_pagefile_fmt[200];
735c2c66affSColin Finck     DWORD_PTR args[2];
736c2c66affSColin Finck 
737c2c66affSColin Finck     hr = add_ui4_property(node, dwDirectXVersionMajor, 9);
738c2c66affSColin Finck     if (FAILED(hr))
739c2c66affSColin Finck         return hr;
740c2c66affSColin Finck 
741c2c66affSColin Finck     hr = add_ui4_property(node, dwDirectXVersionMinor, 0);
742c2c66affSColin Finck     if (FAILED(hr))
743c2c66affSColin Finck         return hr;
744c2c66affSColin Finck 
745c2c66affSColin Finck     hr = add_bstr_property(node, szDirectXVersionLetter, szDirectXVersionLetter_v);
746c2c66affSColin Finck     if (FAILED(hr))
747c2c66affSColin Finck         return hr;
748c2c66affSColin Finck 
749c2c66affSColin Finck     hr = add_bstr_property(node, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
750c2c66affSColin Finck     if (FAILED(hr))
751c2c66affSColin Finck         return hr;
752c2c66affSColin Finck 
753c2c66affSColin Finck     hr = add_bstr_property(node, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
754c2c66affSColin Finck     if (FAILED(hr))
755c2c66affSColin Finck         return hr;
756c2c66affSColin Finck 
757c2c66affSColin Finck     hr = add_bool_property(node, bDebug, FALSE);
758c2c66affSColin Finck     if (FAILED(hr))
759c2c66affSColin Finck         return hr;
760c2c66affSColin Finck 
761c2c66affSColin Finck     hr = add_bool_property(node, bNECPC98, FALSE);
762c2c66affSColin Finck     if (FAILED(hr))
763c2c66affSColin Finck         return hr;
764c2c66affSColin Finck 
765c2c66affSColin Finck     msex.dwLength = sizeof(msex);
766c2c66affSColin Finck     GlobalMemoryStatusEx(&msex);
767c2c66affSColin Finck 
768c2c66affSColin Finck     hr = add_ull_as_bstr_property(node, ullPhysicalMemory, msex.ullTotalPhys);
769c2c66affSColin Finck     if (FAILED(hr))
770c2c66affSColin Finck         return hr;
771c2c66affSColin Finck 
772c2c66affSColin Finck     hr = add_ull_as_bstr_property(node, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
773c2c66affSColin Finck     if (FAILED(hr))
774c2c66affSColin Finck         return hr;
775c2c66affSColin Finck 
776c2c66affSColin Finck     hr = add_ull_as_bstr_property(node, ullAvailPageFile, msex.ullAvailPageFile);
777c2c66affSColin Finck     if (FAILED(hr))
778c2c66affSColin Finck         return hr;
779c2c66affSColin Finck 
780c2c66affSColin Finck     hr = add_bool_property(node, bNetMeetingRunning, is_netmeeting_running());
781c2c66affSColin Finck     if (FAILED(hr))
782c2c66affSColin Finck         return hr;
783c2c66affSColin Finck 
784c2c66affSColin Finck     info.dwOSVersionInfoSize = sizeof(info);
785c2c66affSColin Finck     GetVersionExW(&info);
786c2c66affSColin Finck 
787c2c66affSColin Finck     hr = add_ui4_property(node, dwOSMajorVersion, info.dwMajorVersion);
788c2c66affSColin Finck     if (FAILED(hr))
789c2c66affSColin Finck         return hr;
790c2c66affSColin Finck 
791c2c66affSColin Finck     hr = add_ui4_property(node, dwOSMinorVersion, info.dwMinorVersion);
792c2c66affSColin Finck     if (FAILED(hr))
793c2c66affSColin Finck         return hr;
794c2c66affSColin Finck 
795c2c66affSColin Finck     hr = add_ui4_property(node, dwOSBuildNumber, info.dwBuildNumber);
796c2c66affSColin Finck     if (FAILED(hr))
797c2c66affSColin Finck         return hr;
798c2c66affSColin Finck 
799c2c66affSColin Finck     hr = add_ui4_property(node, dwOSPlatformID, info.dwPlatformId);
800c2c66affSColin Finck     if (FAILED(hr))
801c2c66affSColin Finck         return hr;
802c2c66affSColin Finck 
803c2c66affSColin Finck     hr = add_bstr_property(node, szCSDVersion, info.szCSDVersion);
804c2c66affSColin Finck     if (FAILED(hr))
805c2c66affSColin Finck         return hr;
806c2c66affSColin Finck 
807c2c66affSColin Finck     /* FIXME: Roundoff should not be done with truncated division. */
808*d6c879a0SAmine Khaldi     swprintf(print_buf, physmem_fmtW,
809*d6c879a0SAmine Khaldi               (DWORD)(msex.ullTotalPhys / (1024 * 1024)));
810c2c66affSColin Finck     hr = add_bstr_property(node, szPhysicalMemoryEnglish, print_buf);
811c2c66affSColin Finck     if (FAILED(hr))
812c2c66affSColin Finck         return hr;
813c2c66affSColin Finck 
814c2c66affSColin Finck     usedpage_mb = (DWORD)((msex.ullTotalPageFile - msex.ullAvailPageFile) / (1024 * 1024));
815c2c66affSColin Finck     availpage_mb = (DWORD)(msex.ullAvailPageFile / (1024 * 1024));
816*d6c879a0SAmine Khaldi     LoadStringW(dxdiagn_instance, IDS_PAGE_FILE_FORMAT, localized_pagefile_fmt,
817*d6c879a0SAmine Khaldi                 ARRAY_SIZE(localized_pagefile_fmt));
818c2c66affSColin Finck     args[0] = usedpage_mb;
819c2c66affSColin Finck     args[1] = availpage_mb;
820*d6c879a0SAmine Khaldi     FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY, localized_pagefile_fmt,
821*d6c879a0SAmine Khaldi                    0, 0, print_buf, ARRAY_SIZE(print_buf), (__ms_va_list*)args);
822c2c66affSColin Finck 
823c2c66affSColin Finck     hr = add_bstr_property(node, szPageFileLocalized, print_buf);
824c2c66affSColin Finck     if (FAILED(hr))
825c2c66affSColin Finck         return hr;
826c2c66affSColin Finck 
827*d6c879a0SAmine Khaldi     swprintf(print_buf, pagefile_fmtW, usedpage_mb, availpage_mb);
828c2c66affSColin Finck 
829c2c66affSColin Finck     hr = add_bstr_property(node, szPageFileEnglish, print_buf);
830c2c66affSColin Finck     if (FAILED(hr))
831c2c66affSColin Finck         return hr;
832c2c66affSColin Finck 
833c2c66affSColin Finck     GetWindowsDirectoryW(buffer, MAX_PATH);
834c2c66affSColin Finck 
835c2c66affSColin Finck     hr = add_bstr_property(node, szWindowsDir, buffer);
836c2c66affSColin Finck     if (FAILED(hr))
837c2c66affSColin Finck         return hr;
838c2c66affSColin Finck 
839*d6c879a0SAmine Khaldi     count = ARRAY_SIZE(computer_name);
840c2c66affSColin Finck     if (!GetComputerNameW(computer_name, &count))
841c2c66affSColin Finck         return E_FAIL;
842c2c66affSColin Finck 
843c2c66affSColin Finck     hr = add_bstr_property(node, szMachineNameLocalized, computer_name);
844c2c66affSColin Finck     if (FAILED(hr))
845c2c66affSColin Finck         return hr;
846c2c66affSColin Finck 
847c2c66affSColin Finck     hr = add_bstr_property(node, szMachineNameEnglish, computer_name);
848c2c66affSColin Finck     if (FAILED(hr))
849c2c66affSColin Finck         return hr;
850c2c66affSColin Finck 
851c2c66affSColin Finck     hr = add_bstr_property(node, szSystemManufacturerEnglish, szEmpty);
852c2c66affSColin Finck     if (FAILED(hr))
853c2c66affSColin Finck         return hr;
854c2c66affSColin Finck 
855c2c66affSColin Finck     hr = add_bstr_property(node, szSystemModelEnglish, szEmpty);
856c2c66affSColin Finck     if (FAILED(hr))
857c2c66affSColin Finck         return hr;
858c2c66affSColin Finck 
859c2c66affSColin Finck     hr = add_bstr_property(node, szBIOSEnglish, szEmpty);
860c2c66affSColin Finck     if (FAILED(hr))
861c2c66affSColin Finck         return hr;
862c2c66affSColin Finck 
863c2c66affSColin Finck     hr = fill_processor_information(node);
864c2c66affSColin Finck     if (FAILED(hr))
865c2c66affSColin Finck         return hr;
866c2c66affSColin Finck 
867c2c66affSColin Finck     hr = add_bstr_property(node, szSetupParamEnglish, notpresentW);
868c2c66affSColin Finck     if (FAILED(hr))
869c2c66affSColin Finck         return hr;
870c2c66affSColin Finck 
871c2c66affSColin Finck     hr = add_bstr_property(node, szDxDiagVersion, szEmpty);
872c2c66affSColin Finck     if (FAILED(hr))
873c2c66affSColin Finck         return hr;
874c2c66affSColin Finck 
875c2c66affSColin Finck     hr = fill_language_information(node);
876c2c66affSColin Finck     if (FAILED(hr))
877c2c66affSColin Finck         return hr;
878c2c66affSColin Finck 
879c2c66affSColin Finck     hr = fill_datetime_information(node);
880c2c66affSColin Finck     if (FAILED(hr))
881c2c66affSColin Finck         return hr;
882c2c66affSColin Finck 
883c2c66affSColin Finck     hr = fill_os_string_information(node, &info);
884c2c66affSColin Finck     if (FAILED(hr))
885c2c66affSColin Finck         return hr;
886c2c66affSColin Finck 
887c2c66affSColin Finck     return S_OK;
888c2c66affSColin Finck }
889c2c66affSColin Finck 
890c2c66affSColin Finck /* The logic from pixelformat_for_depth() in dlls/wined3d/utils.c is reversed. */
depth_for_pixelformat(D3DFORMAT format)891c2c66affSColin Finck static DWORD depth_for_pixelformat(D3DFORMAT format)
892c2c66affSColin Finck {
893c2c66affSColin Finck     switch (format)
894c2c66affSColin Finck     {
895c2c66affSColin Finck     case D3DFMT_P8: return 8;
896c2c66affSColin Finck     case D3DFMT_X1R5G5B5: return 15;
897c2c66affSColin Finck     case D3DFMT_R5G6B5: return 16;
898c2c66affSColin Finck     /* This case will fail to distinguish an original bpp of 24. */
899c2c66affSColin Finck     case D3DFMT_X8R8G8B8: return 32;
900c2c66affSColin Finck     default:
901c2c66affSColin Finck         FIXME("Unknown D3DFORMAT %d, returning 32 bpp\n", format);
902c2c66affSColin Finck         return 32;
903c2c66affSColin Finck     }
904c2c66affSColin Finck }
905c2c66affSColin Finck 
get_texture_memory(GUID * adapter,DWORD * available_mem)906c2c66affSColin Finck static BOOL get_texture_memory(GUID *adapter, DWORD *available_mem)
907c2c66affSColin Finck {
908c2c66affSColin Finck     IDirectDraw7 *pDirectDraw;
909c2c66affSColin Finck     HRESULT hr;
910c2c66affSColin Finck     DDSCAPS2 dd_caps;
911c2c66affSColin Finck 
912c2c66affSColin Finck     hr = DirectDrawCreateEx(adapter, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
913c2c66affSColin Finck     if (SUCCEEDED(hr))
914c2c66affSColin Finck     {
915c2c66affSColin Finck         dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
916c2c66affSColin Finck         dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
917c2c66affSColin Finck         hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, available_mem, NULL);
918c2c66affSColin Finck         IDirectDraw7_Release(pDirectDraw);
919c2c66affSColin Finck         if (SUCCEEDED(hr))
920c2c66affSColin Finck             return TRUE;
921c2c66affSColin Finck     }
922c2c66affSColin Finck 
923c2c66affSColin Finck     return FALSE;
924c2c66affSColin Finck }
925c2c66affSColin Finck 
vendor_id_to_manufacturer_string(DWORD vendor_id)926c2c66affSColin Finck static const WCHAR *vendor_id_to_manufacturer_string(DWORD vendor_id)
927c2c66affSColin Finck {
928*d6c879a0SAmine Khaldi     unsigned int i;
929*d6c879a0SAmine Khaldi 
930c2c66affSColin Finck     static const WCHAR atiW[] = {'A','T','I',' ','T','e','c','h','n','o','l','o','g','i','e','s',' ','I','n','c','.',0};
931c2c66affSColin Finck     static const WCHAR nvidiaW[] = {'N','V','I','D','I','A',0};
932c2c66affSColin Finck     static const WCHAR intelW[] = {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
933*d6c879a0SAmine Khaldi     static const WCHAR vmwareW[] = {'V','M','w','a','r','e',0};
934*d6c879a0SAmine Khaldi     static const WCHAR redhatW[] = {'R','e','d',' ','H','a','t',0};
935c2c66affSColin Finck     static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
936*d6c879a0SAmine Khaldi     static const struct
937c2c66affSColin Finck     {
938*d6c879a0SAmine Khaldi         DWORD id;
939*d6c879a0SAmine Khaldi         const WCHAR *name;
940*d6c879a0SAmine Khaldi     }
941*d6c879a0SAmine Khaldi     vendors[] =
942*d6c879a0SAmine Khaldi     {
943*d6c879a0SAmine Khaldi         {0x1002, atiW},
944*d6c879a0SAmine Khaldi         {0x10de, nvidiaW},
945*d6c879a0SAmine Khaldi         {0x15ad, vmwareW},
946*d6c879a0SAmine Khaldi         {0x1af4, redhatW},
947*d6c879a0SAmine Khaldi         {0x8086, intelW},
948c2c66affSColin Finck     };
949c2c66affSColin Finck 
950*d6c879a0SAmine Khaldi     for (i = 0; i < ARRAY_SIZE(vendors); ++i)
951c2c66affSColin Finck     {
952*d6c879a0SAmine Khaldi         if (vendors[i].id == vendor_id)
953*d6c879a0SAmine Khaldi             return vendors[i].name;
954c2c66affSColin Finck     }
955*d6c879a0SAmine Khaldi 
956*d6c879a0SAmine Khaldi     FIXME("Unknown PCI vendor ID 0x%04x.\n", vendor_id);
957*d6c879a0SAmine Khaldi 
958*d6c879a0SAmine Khaldi     return unknownW;
959c2c66affSColin Finck }
960c2c66affSColin Finck 
fill_display_information_d3d(IDxDiagContainerImpl_Container * node)961c2c66affSColin Finck static HRESULT fill_display_information_d3d(IDxDiagContainerImpl_Container *node)
962c2c66affSColin Finck {
963c2c66affSColin Finck     IDxDiagContainerImpl_Container *display_adapter;
964c2c66affSColin Finck     HRESULT hr;
965c2c66affSColin Finck     IDirect3D9 *pDirect3D9;
966c2c66affSColin Finck     WCHAR buffer[256];
967c2c66affSColin Finck     UINT index, count;
968c2c66affSColin Finck 
969c2c66affSColin Finck     pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);
970c2c66affSColin Finck     if (!pDirect3D9)
971c2c66affSColin Finck         return E_FAIL;
972c2c66affSColin Finck 
973c2c66affSColin Finck     count = IDirect3D9_GetAdapterCount(pDirect3D9);
974c2c66affSColin Finck     for (index = 0; index < count; index++)
975c2c66affSColin Finck     {
976c2c66affSColin Finck         static const WCHAR adapterid_fmtW[] = {'%','u',0};
977c2c66affSColin Finck         static const WCHAR driverversion_fmtW[] = {'%','u','.','%','u','.','%','0','4','u','.','%','0','4','u',0};
978c2c66affSColin Finck         static const WCHAR id_fmtW[] = {'0','x','%','0','4','x',0};
979c2c66affSColin Finck         static const WCHAR subsysid_fmtW[] = {'0','x','%','0','8','x',0};
980c2c66affSColin Finck         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
981c2c66affSColin Finck         static const WCHAR b3DAccelerationExists[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','x','i','s','t','s',0};
982c2c66affSColin Finck         static const WCHAR b3DAccelerationEnabled[] = {'b','3','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
983c2c66affSColin Finck         static const WCHAR bDDAccelerationEnabled[] = {'b','D','D','A','c','c','e','l','e','r','a','t','i','o','n','E','n','a','b','l','e','d',0};
984c2c66affSColin Finck         static const WCHAR bNoHardware[] = {'b','N','o','H','a','r','d','w','a','r','e',0};
985afc3201bSAmine Khaldi         static const WCHAR mode_fmtW[] = {'%','d',' ','x',' ','%','d',' ','(','%','d',' ','b','i','t',')',' ','(','%','d','H','z',')',0};
986afc3201bSAmine Khaldi         static const WCHAR gernericPNPMonitorW[] = {'G','e','n','e','r','i','c',' ','P','n','P',' ','M','o','n','i','t','o','r',0};
987afc3201bSAmine Khaldi         static const WCHAR failedToGetParameterW[] = {'F','a','i','l','e','d',' ','t','o',' ','g','e','t',' ','p','a','r','a','m','e','t','e','r',0};
988afc3201bSAmine Khaldi         static const WCHAR driverAttributesW[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
989afc3201bSAmine Khaldi         static const WCHAR englishW[] = {'E','n','g','l','i','s','h',0};
990afc3201bSAmine Khaldi         static const WCHAR driverDateEnglishW[] = {'1','/','1','/','2','0','1','6',' ','1','0',':','0','0',':','0','0',0};
991afc3201bSAmine Khaldi         static const WCHAR driverDateLocalW[] = {'1','/','1','/','2','0','1','6',' ','1','0',':','0','0',':','0','0',' ','A','M',0};
992afc3201bSAmine Khaldi         static const WCHAR naW[] = {'n','/','a',0};
993afc3201bSAmine Khaldi         static const WCHAR ddi11W[] = {'1','1',0};
994c2c66affSColin Finck 
995c2c66affSColin Finck         D3DADAPTER_IDENTIFIER9 adapter_info;
996c2c66affSColin Finck         D3DDISPLAYMODE adapter_mode;
997c2c66affSColin Finck         D3DCAPS9 device_caps;
998c2c66affSColin Finck         DWORD available_mem = 0;
999c2c66affSColin Finck         BOOL hardware_accel;
1000c2c66affSColin Finck 
1001*d6c879a0SAmine Khaldi         swprintf(buffer, adapterid_fmtW, index);
1002c2c66affSColin Finck         display_adapter = allocate_information_node(buffer);
1003c2c66affSColin Finck         if (!display_adapter)
1004c2c66affSColin Finck         {
1005c2c66affSColin Finck             hr = E_OUTOFMEMORY;
1006c2c66affSColin Finck             goto cleanup;
1007c2c66affSColin Finck         }
1008c2c66affSColin Finck 
1009c2c66affSColin Finck         add_subcontainer(node, display_adapter);
1010c2c66affSColin Finck 
1011c2c66affSColin Finck         hr = IDirect3D9_GetAdapterIdentifier(pDirect3D9, index, 0, &adapter_info);
1012c2c66affSColin Finck         if (SUCCEEDED(hr))
1013c2c66affSColin Finck         {
1014c2c66affSColin Finck             WCHAR driverW[sizeof(adapter_info.Driver)];
1015c2c66affSColin Finck             WCHAR descriptionW[sizeof(adapter_info.Description)];
1016c2c66affSColin Finck             WCHAR devicenameW[sizeof(adapter_info.DeviceName)];
1017c2c66affSColin Finck 
1018*d6c879a0SAmine Khaldi             MultiByteToWideChar(CP_ACP, 0, adapter_info.Driver, -1, driverW, ARRAY_SIZE(driverW));
1019*d6c879a0SAmine Khaldi             MultiByteToWideChar(CP_ACP, 0, adapter_info.Description, -1, descriptionW,
1020*d6c879a0SAmine Khaldi                                 ARRAY_SIZE(descriptionW));
1021*d6c879a0SAmine Khaldi             MultiByteToWideChar(CP_ACP, 0, adapter_info.DeviceName, -1, devicenameW,
1022*d6c879a0SAmine Khaldi                                 ARRAY_SIZE(devicenameW));
1023c2c66affSColin Finck 
1024c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDriverName, driverW);
1025c2c66affSColin Finck             if (FAILED(hr))
1026c2c66affSColin Finck                 goto cleanup;
1027c2c66affSColin Finck 
1028c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDescription, descriptionW);
1029c2c66affSColin Finck             if (FAILED(hr))
1030c2c66affSColin Finck                 goto cleanup;
1031c2c66affSColin Finck 
1032c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDeviceName, devicenameW);
1033c2c66affSColin Finck             if (FAILED(hr))
1034c2c66affSColin Finck                 goto cleanup;
1035c2c66affSColin Finck 
1036*d6c879a0SAmine Khaldi             swprintf(buffer, driverversion_fmtW,
1037c2c66affSColin Finck                       HIWORD(adapter_info.DriverVersion.u.HighPart), LOWORD(adapter_info.DriverVersion.u.HighPart),
1038c2c66affSColin Finck                       HIWORD(adapter_info.DriverVersion.u.LowPart), LOWORD(adapter_info.DriverVersion.u.LowPart));
1039c2c66affSColin Finck 
1040c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDriverVersion, buffer);
1041c2c66affSColin Finck             if (FAILED(hr))
1042c2c66affSColin Finck                 goto cleanup;
1043c2c66affSColin Finck 
1044*d6c879a0SAmine Khaldi             swprintf(buffer, id_fmtW, adapter_info.VendorId);
1045c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szVendorId, buffer);
1046c2c66affSColin Finck             if (FAILED(hr))
1047c2c66affSColin Finck                 goto cleanup;
1048c2c66affSColin Finck 
1049*d6c879a0SAmine Khaldi             swprintf(buffer, id_fmtW, adapter_info.DeviceId);
1050c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDeviceId, buffer);
1051c2c66affSColin Finck             if (FAILED(hr))
1052c2c66affSColin Finck                 goto cleanup;
1053c2c66affSColin Finck 
1054*d6c879a0SAmine Khaldi             swprintf(buffer, subsysid_fmtW, adapter_info.SubSysId);
1055c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szSubSysId, buffer);
1056c2c66affSColin Finck             if (FAILED(hr))
1057c2c66affSColin Finck                 goto cleanup;
1058c2c66affSColin Finck 
1059*d6c879a0SAmine Khaldi             swprintf(buffer, id_fmtW, adapter_info.Revision);
1060c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szRevisionId, buffer);
1061c2c66affSColin Finck             if (FAILED(hr))
1062c2c66affSColin Finck                 goto cleanup;
1063c2c66affSColin Finck 
1064c2c66affSColin Finck             StringFromGUID2(&adapter_info.DeviceIdentifier, buffer, 39);
1065c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szDeviceIdentifier, buffer);
1066c2c66affSColin Finck             if (FAILED(hr))
1067c2c66affSColin Finck                 goto cleanup;
1068c2c66affSColin Finck 
1069c2c66affSColin Finck             hr = add_bstr_property(display_adapter, szManufacturer, vendor_id_to_manufacturer_string(adapter_info.VendorId));
1070c2c66affSColin Finck             if (FAILED(hr))
1071c2c66affSColin Finck                 goto cleanup;
1072c2c66affSColin Finck         }
1073c2c66affSColin Finck 
1074c2c66affSColin Finck         hr = IDirect3D9_GetAdapterDisplayMode(pDirect3D9, index, &adapter_mode);
1075c2c66affSColin Finck         if (SUCCEEDED(hr))
1076c2c66affSColin Finck         {
1077c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwWidth, adapter_mode.Width);
1078c2c66affSColin Finck             if (FAILED(hr))
1079c2c66affSColin Finck                 goto cleanup;
1080c2c66affSColin Finck 
1081c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwHeight, adapter_mode.Height);
1082c2c66affSColin Finck             if (FAILED(hr))
1083c2c66affSColin Finck                 goto cleanup;
1084c2c66affSColin Finck 
1085c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwRefreshRate, adapter_mode.RefreshRate);
1086c2c66affSColin Finck             if (FAILED(hr))
1087c2c66affSColin Finck                 goto cleanup;
1088c2c66affSColin Finck 
1089c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwBpp, depth_for_pixelformat(adapter_mode.Format));
1090c2c66affSColin Finck             if (FAILED(hr))
1091c2c66affSColin Finck                 goto cleanup;
1092afc3201bSAmine Khaldi 
1093*d6c879a0SAmine Khaldi             swprintf(buffer, mode_fmtW, adapter_mode.Width, adapter_mode.Height,
1094afc3201bSAmine Khaldi                       depth_for_pixelformat(adapter_mode.Format), adapter_mode.RefreshRate);
1095afc3201bSAmine Khaldi 
1096afc3201bSAmine Khaldi             hr = add_bstr_property(display_adapter, szDisplayModeLocalized, buffer);
1097afc3201bSAmine Khaldi             if (FAILED(hr))
1098afc3201bSAmine Khaldi                 goto cleanup;
1099afc3201bSAmine Khaldi 
1100afc3201bSAmine Khaldi             hr = add_bstr_property(display_adapter, szDisplayModeEnglish, buffer);
1101afc3201bSAmine Khaldi             if (FAILED(hr))
1102afc3201bSAmine Khaldi                 goto cleanup;
1103c2c66affSColin Finck         }
1104c2c66affSColin Finck 
1105c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szKeyDeviceKey, szEmpty);
1106c2c66affSColin Finck         if (FAILED(hr))
1107c2c66affSColin Finck             goto cleanup;
1108c2c66affSColin Finck 
1109c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szKeyDeviceID, szEmpty);
1110c2c66affSColin Finck         if (FAILED(hr))
1111c2c66affSColin Finck             goto cleanup;
1112c2c66affSColin Finck 
1113c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szChipType, szEmpty);
1114c2c66affSColin Finck         if (FAILED(hr))
1115c2c66affSColin Finck             goto cleanup;
1116c2c66affSColin Finck 
1117c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDACType, szEmpty);
1118c2c66affSColin Finck         if (FAILED(hr))
1119c2c66affSColin Finck             goto cleanup;
1120c2c66affSColin Finck 
1121c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szRevision, szEmpty);
1122c2c66affSColin Finck         if (FAILED(hr))
1123c2c66affSColin Finck             goto cleanup;
1124c2c66affSColin Finck 
1125c2c66affSColin Finck         if (!get_texture_memory(&adapter_info.DeviceIdentifier, &available_mem))
1126c2c66affSColin Finck             WARN("get_texture_memory helper failed\n");
1127c2c66affSColin Finck 
1128*d6c879a0SAmine Khaldi         swprintf(buffer, mem_fmt, available_mem / 1000000.0f);
1129c2c66affSColin Finck 
1130c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1131c2c66affSColin Finck         if (FAILED(hr))
1132c2c66affSColin Finck             goto cleanup;
1133c2c66affSColin Finck 
1134c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1135c2c66affSColin Finck         if (FAILED(hr))
1136c2c66affSColin Finck             goto cleanup;
1137c2c66affSColin Finck 
1138c2c66affSColin Finck         hr = IDirect3D9_GetDeviceCaps(pDirect3D9, index, D3DDEVTYPE_HAL, &device_caps);
1139c2c66affSColin Finck         hardware_accel = SUCCEEDED(hr);
1140c2c66affSColin Finck 
1141c2c66affSColin Finck         hr = add_bool_property(display_adapter, b3DAccelerationEnabled, hardware_accel);
1142c2c66affSColin Finck         if (FAILED(hr))
1143c2c66affSColin Finck             goto cleanup;
1144c2c66affSColin Finck 
1145c2c66affSColin Finck         hr = add_bool_property(display_adapter, b3DAccelerationExists, hardware_accel);
1146c2c66affSColin Finck         if (FAILED(hr))
1147c2c66affSColin Finck             goto cleanup;
1148c2c66affSColin Finck 
1149c2c66affSColin Finck         hr = add_bool_property(display_adapter, bDDAccelerationEnabled, hardware_accel);
1150c2c66affSColin Finck         if (FAILED(hr))
1151c2c66affSColin Finck             goto cleanup;
1152c2c66affSColin Finck 
1153c2c66affSColin Finck         hr = add_bool_property(display_adapter, bNoHardware, FALSE);
1154c2c66affSColin Finck         if (FAILED(hr))
1155c2c66affSColin Finck             goto cleanup;
1156afc3201bSAmine Khaldi 
1157afc3201bSAmine Khaldi         hr = add_bool_property(display_adapter, bCanRenderWindow, TRUE);
1158afc3201bSAmine Khaldi         if (FAILED(hr))
1159afc3201bSAmine Khaldi             goto cleanup;
1160afc3201bSAmine Khaldi 
1161afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szMonitorName, gernericPNPMonitorW);
1162afc3201bSAmine Khaldi         if (FAILED(hr))
1163afc3201bSAmine Khaldi             goto cleanup;
1164afc3201bSAmine Khaldi 
1165afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szMonitorMaxRes, failedToGetParameterW);
1166afc3201bSAmine Khaldi         if (FAILED(hr))
1167afc3201bSAmine Khaldi             goto cleanup;
1168afc3201bSAmine Khaldi 
1169afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverAttributes, driverAttributesW);
1170afc3201bSAmine Khaldi         if (FAILED(hr))
1171afc3201bSAmine Khaldi             goto cleanup;
1172afc3201bSAmine Khaldi 
1173afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverLanguageEnglish, englishW);
1174afc3201bSAmine Khaldi         if (FAILED(hr))
1175afc3201bSAmine Khaldi             goto cleanup;
1176afc3201bSAmine Khaldi 
1177afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverLanguageLocalized, englishW);
1178afc3201bSAmine Khaldi         if (FAILED(hr))
1179afc3201bSAmine Khaldi             goto cleanup;
1180afc3201bSAmine Khaldi 
1181afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverDateEnglish, driverDateEnglishW);
1182afc3201bSAmine Khaldi         if (FAILED(hr))
1183afc3201bSAmine Khaldi             goto cleanup;
1184afc3201bSAmine Khaldi 
1185afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverDateLocalized, driverDateLocalW);
1186afc3201bSAmine Khaldi         if (FAILED(hr))
1187afc3201bSAmine Khaldi             goto cleanup;
1188afc3201bSAmine Khaldi 
1189afc3201bSAmine Khaldi         hr = add_i4_property(display_adapter, lDriverSize, 10 * 1024 * 1024);
1190afc3201bSAmine Khaldi         if (FAILED(hr))
1191afc3201bSAmine Khaldi             goto cleanup;
1192afc3201bSAmine Khaldi 
1193afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szMiniVdd, naW);
1194afc3201bSAmine Khaldi         if (FAILED(hr))
1195afc3201bSAmine Khaldi             goto cleanup;
1196afc3201bSAmine Khaldi 
1197afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szMiniVddDateLocalized, naW);
1198afc3201bSAmine Khaldi         if (FAILED(hr))
1199afc3201bSAmine Khaldi             goto cleanup;
1200afc3201bSAmine Khaldi 
1201afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szMiniVddDateEnglish, naW);
1202afc3201bSAmine Khaldi         if (FAILED(hr))
1203afc3201bSAmine Khaldi             goto cleanup;
1204afc3201bSAmine Khaldi 
1205afc3201bSAmine Khaldi         hr = add_i4_property(display_adapter, lMiniVddSize, 0);
1206afc3201bSAmine Khaldi         if (FAILED(hr))
1207afc3201bSAmine Khaldi             goto cleanup;
1208afc3201bSAmine Khaldi 
1209afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szVdd, naW);
1210afc3201bSAmine Khaldi         if (FAILED(hr))
1211afc3201bSAmine Khaldi             goto cleanup;
1212afc3201bSAmine Khaldi 
1213afc3201bSAmine Khaldi         hr = add_bool_property(display_adapter, bDriverBeta, FALSE);
1214afc3201bSAmine Khaldi         if (FAILED(hr))
1215afc3201bSAmine Khaldi             goto cleanup;
1216afc3201bSAmine Khaldi 
1217afc3201bSAmine Khaldi         hr = add_bool_property(display_adapter, bDriverDebug, FALSE);
1218afc3201bSAmine Khaldi         if (FAILED(hr))
1219afc3201bSAmine Khaldi             goto cleanup;
1220afc3201bSAmine Khaldi 
1221afc3201bSAmine Khaldi         hr = add_bool_property(display_adapter, bDriverSigned, TRUE);
1222afc3201bSAmine Khaldi         if (FAILED(hr))
1223afc3201bSAmine Khaldi             goto cleanup;
1224afc3201bSAmine Khaldi 
1225afc3201bSAmine Khaldi         hr = add_bool_property(display_adapter, bDriverSignedValid, TRUE);
1226afc3201bSAmine Khaldi         if (FAILED(hr))
1227afc3201bSAmine Khaldi             goto cleanup;
1228afc3201bSAmine Khaldi 
1229afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDriverSignDate, naW);
1230afc3201bSAmine Khaldi         if (FAILED(hr))
1231afc3201bSAmine Khaldi             goto cleanup;
1232afc3201bSAmine Khaldi 
1233afc3201bSAmine Khaldi         hr = add_ui4_property(display_adapter, dwDDIVersion, 11);
1234afc3201bSAmine Khaldi         if (FAILED(hr))
1235afc3201bSAmine Khaldi             goto cleanup;
1236afc3201bSAmine Khaldi 
1237afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDDIVersionEnglish, ddi11W);
1238afc3201bSAmine Khaldi         if (FAILED(hr))
1239afc3201bSAmine Khaldi             goto cleanup;
1240afc3201bSAmine Khaldi 
1241afc3201bSAmine Khaldi         hr = add_bstr_property(display_adapter, szDDIVersionLocalized, ddi11W);
1242afc3201bSAmine Khaldi         if (FAILED(hr))
1243afc3201bSAmine Khaldi             goto cleanup;
1244afc3201bSAmine Khaldi 
1245afc3201bSAmine Khaldi         hr = add_ui4_property(display_adapter, iAdapter, index);
1246afc3201bSAmine Khaldi         if (FAILED(hr))
1247afc3201bSAmine Khaldi             goto cleanup;
1248afc3201bSAmine Khaldi 
1249afc3201bSAmine Khaldi         hr = add_ui4_property(display_adapter, dwWHQLLevel, 0);
1250afc3201bSAmine Khaldi         if (FAILED(hr))
1251afc3201bSAmine Khaldi             goto cleanup;
1252c2c66affSColin Finck     }
1253c2c66affSColin Finck 
1254c2c66affSColin Finck     hr = S_OK;
1255c2c66affSColin Finck cleanup:
1256c2c66affSColin Finck     IDirect3D9_Release(pDirect3D9);
1257c2c66affSColin Finck     return hr;
1258c2c66affSColin Finck }
1259c2c66affSColin Finck 
fill_display_information_fallback(IDxDiagContainerImpl_Container * node)1260c2c66affSColin Finck static HRESULT fill_display_information_fallback(IDxDiagContainerImpl_Container *node)
1261c2c66affSColin Finck {
1262c2c66affSColin Finck     static const WCHAR szAdapterID[] = {'0',0};
1263c2c66affSColin Finck     static const WCHAR *empty_properties[] = {szDeviceIdentifier, szVendorId, szDeviceId,
1264c2c66affSColin Finck                                               szKeyDeviceKey, szKeyDeviceID, szDriverName,
1265c2c66affSColin Finck                                               szDriverVersion, szSubSysId, szRevisionId,
1266c2c66affSColin Finck                                               szManufacturer, szChipType, szDACType, szRevision};
1267c2c66affSColin Finck 
1268c2c66affSColin Finck     IDxDiagContainerImpl_Container *display_adapter;
1269c2c66affSColin Finck     HRESULT hr;
1270c2c66affSColin Finck     IDirectDraw7 *pDirectDraw;
1271c2c66affSColin Finck     DDSCAPS2 dd_caps;
1272c2c66affSColin Finck     DISPLAY_DEVICEW disp_dev;
1273c2c66affSColin Finck     DDSURFACEDESC2 surface_descr;
1274c2c66affSColin Finck     DWORD tmp;
1275c2c66affSColin Finck     WCHAR buffer[256];
1276c2c66affSColin Finck 
1277c2c66affSColin Finck     display_adapter = allocate_information_node(szAdapterID);
1278c2c66affSColin Finck     if (!display_adapter)
1279c2c66affSColin Finck         return E_OUTOFMEMORY;
1280c2c66affSColin Finck 
1281c2c66affSColin Finck     add_subcontainer(node, display_adapter);
1282c2c66affSColin Finck 
1283c2c66affSColin Finck     disp_dev.cb = sizeof(disp_dev);
1284c2c66affSColin Finck     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
1285c2c66affSColin Finck     {
1286c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDeviceName, disp_dev.DeviceName);
1287c2c66affSColin Finck         if (FAILED(hr))
1288c2c66affSColin Finck             return hr;
1289c2c66affSColin Finck 
1290c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDescription, disp_dev.DeviceString);
1291c2c66affSColin Finck         if (FAILED(hr))
1292c2c66affSColin Finck             return hr;
1293c2c66affSColin Finck     }
1294c2c66affSColin Finck 
1295c2c66affSColin Finck     /* Silently ignore a failure from DirectDrawCreateEx. */
1296c2c66affSColin Finck     hr = DirectDrawCreateEx(NULL, (void **)&pDirectDraw, &IID_IDirectDraw7, NULL);
1297c2c66affSColin Finck     if (FAILED(hr))
1298c2c66affSColin Finck         return S_OK;
1299c2c66affSColin Finck 
1300c2c66affSColin Finck     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
1301c2c66affSColin Finck     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.u1.dwCaps4 = 0;
1302c2c66affSColin Finck     hr = IDirectDraw7_GetAvailableVidMem(pDirectDraw, &dd_caps, &tmp, NULL);
1303c2c66affSColin Finck     if (SUCCEEDED(hr))
1304c2c66affSColin Finck     {
1305c2c66affSColin Finck         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
1306c2c66affSColin Finck 
1307*d6c879a0SAmine Khaldi         swprintf(buffer, mem_fmt, tmp / 1000000.0f);
1308c2c66affSColin Finck 
1309c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDisplayMemoryLocalized, buffer);
1310c2c66affSColin Finck         if (FAILED(hr))
1311c2c66affSColin Finck             goto cleanup;
1312c2c66affSColin Finck 
1313c2c66affSColin Finck         hr = add_bstr_property(display_adapter, szDisplayMemoryEnglish, buffer);
1314c2c66affSColin Finck         if (FAILED(hr))
1315c2c66affSColin Finck             goto cleanup;
1316c2c66affSColin Finck     }
1317c2c66affSColin Finck 
1318c2c66affSColin Finck     surface_descr.dwSize = sizeof(surface_descr);
1319c2c66affSColin Finck     hr = IDirectDraw7_GetDisplayMode(pDirectDraw, &surface_descr);
1320c2c66affSColin Finck     if (SUCCEEDED(hr))
1321c2c66affSColin Finck     {
1322c2c66affSColin Finck         if (surface_descr.dwFlags & DDSD_WIDTH)
1323c2c66affSColin Finck         {
1324c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwWidth, surface_descr.dwWidth);
1325c2c66affSColin Finck             if (FAILED(hr))
1326c2c66affSColin Finck                 goto cleanup;
1327c2c66affSColin Finck         }
1328c2c66affSColin Finck 
1329c2c66affSColin Finck         if (surface_descr.dwFlags & DDSD_HEIGHT)
1330c2c66affSColin Finck         {
1331c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwHeight, surface_descr.dwHeight);
1332c2c66affSColin Finck             if (FAILED(hr))
1333c2c66affSColin Finck                 goto cleanup;
1334c2c66affSColin Finck         }
1335c2c66affSColin Finck 
1336c2c66affSColin Finck         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
1337c2c66affSColin Finck         {
1338c2c66affSColin Finck             hr = add_ui4_property(display_adapter, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1339c2c66affSColin Finck             if (FAILED(hr))
1340c2c66affSColin Finck                 goto cleanup;
1341c2c66affSColin Finck         }
1342c2c66affSColin Finck     }
1343c2c66affSColin Finck 
1344c2c66affSColin Finck     hr = add_ui4_property(display_adapter, dwRefreshRate, 60);
1345c2c66affSColin Finck     if (FAILED(hr))
1346c2c66affSColin Finck         goto cleanup;
1347c2c66affSColin Finck 
1348*d6c879a0SAmine Khaldi     for (tmp = 0; tmp < ARRAY_SIZE(empty_properties); tmp++)
1349c2c66affSColin Finck     {
1350c2c66affSColin Finck         hr = add_bstr_property(display_adapter, empty_properties[tmp], szEmpty);
1351c2c66affSColin Finck         if (FAILED(hr))
1352c2c66affSColin Finck             goto cleanup;
1353c2c66affSColin Finck     }
1354c2c66affSColin Finck 
1355c2c66affSColin Finck     hr = S_OK;
1356c2c66affSColin Finck cleanup:
1357c2c66affSColin Finck     IDirectDraw7_Release(pDirectDraw);
1358c2c66affSColin Finck     return hr;
1359c2c66affSColin Finck }
1360c2c66affSColin Finck 
build_displaydevices_tree(IDxDiagContainerImpl_Container * node)1361c2c66affSColin Finck static HRESULT build_displaydevices_tree(IDxDiagContainerImpl_Container *node)
1362c2c66affSColin Finck {
1363c2c66affSColin Finck     HRESULT hr;
1364c2c66affSColin Finck 
1365c2c66affSColin Finck     /* Try to use Direct3D to obtain the required information first. */
1366c2c66affSColin Finck     hr = fill_display_information_d3d(node);
1367c2c66affSColin Finck     if (hr != E_FAIL)
1368c2c66affSColin Finck         return hr;
1369c2c66affSColin Finck 
1370c2c66affSColin Finck     return fill_display_information_fallback(node);
1371c2c66affSColin Finck }
1372c2c66affSColin Finck 
1373afc3201bSAmine Khaldi struct enum_context
1374afc3201bSAmine Khaldi {
1375afc3201bSAmine Khaldi     IDxDiagContainerImpl_Container *cont;
1376afc3201bSAmine Khaldi     HRESULT hr;
1377afc3201bSAmine Khaldi     int index;
1378afc3201bSAmine Khaldi };
1379afc3201bSAmine Khaldi 
1380afc3201bSAmine Khaldi static const WCHAR szGUIDFmt[] =
1381afc3201bSAmine Khaldi {
1382afc3201bSAmine Khaldi     '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%','0',
1383afc3201bSAmine Khaldi     '2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2',
1384afc3201bSAmine Khaldi     'x','%','0','2','x','%','0','2','x','%','0','2','x',0
1385afc3201bSAmine Khaldi };
1386afc3201bSAmine Khaldi 
guid_to_string(LPWSTR lpwstr,REFGUID lpcguid)1387afc3201bSAmine Khaldi static LPWSTR guid_to_string(LPWSTR lpwstr, REFGUID lpcguid)
1388afc3201bSAmine Khaldi {
1389afc3201bSAmine Khaldi     wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
1390afc3201bSAmine Khaldi         lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
1391afc3201bSAmine Khaldi         lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
1392afc3201bSAmine Khaldi         lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
1393afc3201bSAmine Khaldi 
1394afc3201bSAmine Khaldi     return lpwstr;
1395afc3201bSAmine Khaldi }
1396afc3201bSAmine Khaldi 
dsound_enum(LPGUID guid,LPCWSTR desc,LPCWSTR module,LPVOID context)1397afc3201bSAmine Khaldi BOOL CALLBACK dsound_enum(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID context)
1398afc3201bSAmine Khaldi {
1399afc3201bSAmine Khaldi     static const WCHAR deviceid_fmtW[] = {'%','u',0};
1400afc3201bSAmine Khaldi     static const WCHAR szGuidDeviceID[] = {'s','z','G','u','i','d','D','e','v','i','c','e','I','D',0};
1401afc3201bSAmine Khaldi     static const WCHAR szDriverPath[] = {'s','z','D','r','i','v','e','r','P','a','t','h',0};
1402afc3201bSAmine Khaldi 
1403afc3201bSAmine Khaldi     struct enum_context *enum_ctx = context;
1404afc3201bSAmine Khaldi     IDxDiagContainerImpl_Container *device;
1405afc3201bSAmine Khaldi     WCHAR buffer[256];
1406afc3201bSAmine Khaldi     const WCHAR *p, *name;
1407afc3201bSAmine Khaldi 
1408afc3201bSAmine Khaldi     /* the default device is enumerated twice, one time without GUID */
1409afc3201bSAmine Khaldi     if (!guid) return TRUE;
1410afc3201bSAmine Khaldi 
1411*d6c879a0SAmine Khaldi     _snwprintf(buffer, sizeof(buffer)/sizeof(WCHAR), deviceid_fmtW, enum_ctx->index);
1412afc3201bSAmine Khaldi     device = allocate_information_node(buffer);
1413afc3201bSAmine Khaldi     if (!device)
1414afc3201bSAmine Khaldi     {
1415afc3201bSAmine Khaldi         enum_ctx->hr = E_OUTOFMEMORY;
1416afc3201bSAmine Khaldi         return FALSE;
1417afc3201bSAmine Khaldi     }
1418afc3201bSAmine Khaldi 
1419afc3201bSAmine Khaldi     add_subcontainer(enum_ctx->cont, device);
1420afc3201bSAmine Khaldi 
1421afc3201bSAmine Khaldi     guid_to_string(buffer, guid);
1422afc3201bSAmine Khaldi     enum_ctx->hr = add_bstr_property(device, szGuidDeviceID, buffer);
1423afc3201bSAmine Khaldi     if (FAILED(enum_ctx->hr))
1424afc3201bSAmine Khaldi         return FALSE;
1425afc3201bSAmine Khaldi 
1426afc3201bSAmine Khaldi     enum_ctx->hr = add_bstr_property(device, szDescription, desc);
1427afc3201bSAmine Khaldi     if (FAILED(enum_ctx->hr))
1428afc3201bSAmine Khaldi         return FALSE;
1429afc3201bSAmine Khaldi 
1430afc3201bSAmine Khaldi     enum_ctx->hr = add_bstr_property(device, szDriverPath, module);
1431afc3201bSAmine Khaldi     if (FAILED(enum_ctx->hr))
1432afc3201bSAmine Khaldi         return FALSE;
1433afc3201bSAmine Khaldi 
1434afc3201bSAmine Khaldi     name = module;
1435*d6c879a0SAmine Khaldi     if ((p = wcsrchr(name, '\\'))) name = p + 1;
1436*d6c879a0SAmine Khaldi     if ((p = wcsrchr(name, '/'))) name = p + 1;
1437afc3201bSAmine Khaldi 
1438afc3201bSAmine Khaldi     enum_ctx->hr = add_bstr_property(device, szDriverName, name);
1439afc3201bSAmine Khaldi     if (FAILED(enum_ctx->hr))
1440afc3201bSAmine Khaldi         return FALSE;
1441afc3201bSAmine Khaldi 
1442afc3201bSAmine Khaldi     enum_ctx->index++;
1443afc3201bSAmine Khaldi     return TRUE;
1444afc3201bSAmine Khaldi }
1445afc3201bSAmine Khaldi 
build_directsound_tree(IDxDiagContainerImpl_Container * node)1446c2c66affSColin Finck static HRESULT build_directsound_tree(IDxDiagContainerImpl_Container *node)
1447c2c66affSColin Finck {
1448c2c66affSColin Finck     static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
1449c2c66affSColin Finck     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};
1450c2c66affSColin Finck 
1451afc3201bSAmine Khaldi     struct enum_context enum_ctx;
1452c2c66affSColin Finck     IDxDiagContainerImpl_Container *cont;
1453c2c66affSColin Finck 
1454c2c66affSColin Finck     cont = allocate_information_node(DxDiag_SoundDevices);
1455c2c66affSColin Finck     if (!cont)
1456c2c66affSColin Finck         return E_OUTOFMEMORY;
1457c2c66affSColin Finck 
1458c2c66affSColin Finck     add_subcontainer(node, cont);
1459c2c66affSColin Finck 
1460afc3201bSAmine Khaldi     enum_ctx.cont = cont;
1461afc3201bSAmine Khaldi     enum_ctx.hr = S_OK;
1462afc3201bSAmine Khaldi     enum_ctx.index = 0;
1463afc3201bSAmine Khaldi 
1464afc3201bSAmine Khaldi     DirectSoundEnumerateW(dsound_enum, &enum_ctx);
1465afc3201bSAmine Khaldi     if (FAILED(enum_ctx.hr))
1466afc3201bSAmine Khaldi         return enum_ctx.hr;
1467afc3201bSAmine Khaldi 
1468c2c66affSColin Finck     cont = allocate_information_node(DxDiag_SoundCaptureDevices);
1469c2c66affSColin Finck     if (!cont)
1470c2c66affSColin Finck         return E_OUTOFMEMORY;
1471c2c66affSColin Finck 
1472c2c66affSColin Finck     add_subcontainer(node, cont);
1473c2c66affSColin Finck 
1474afc3201bSAmine Khaldi     enum_ctx.cont = cont;
1475afc3201bSAmine Khaldi     enum_ctx.hr = S_OK;
1476afc3201bSAmine Khaldi     enum_ctx.index = 0;
1477afc3201bSAmine Khaldi 
1478afc3201bSAmine Khaldi     DirectSoundCaptureEnumerateW(dsound_enum, &enum_ctx);
1479afc3201bSAmine Khaldi     if (FAILED(enum_ctx.hr))
1480afc3201bSAmine Khaldi         return enum_ctx.hr;
1481afc3201bSAmine Khaldi 
1482c2c66affSColin Finck     return S_OK;
1483c2c66affSColin Finck }
1484c2c66affSColin Finck 
build_directmusic_tree(IDxDiagContainerImpl_Container * node)1485c2c66affSColin Finck static HRESULT build_directmusic_tree(IDxDiagContainerImpl_Container *node)
1486c2c66affSColin Finck {
1487c2c66affSColin Finck     return S_OK;
1488c2c66affSColin Finck }
1489c2c66affSColin Finck 
build_directinput_tree(IDxDiagContainerImpl_Container * node)1490c2c66affSColin Finck static HRESULT build_directinput_tree(IDxDiagContainerImpl_Container *node)
1491c2c66affSColin Finck {
1492c2c66affSColin Finck     return S_OK;
1493c2c66affSColin Finck }
1494c2c66affSColin Finck 
build_directplay_tree(IDxDiagContainerImpl_Container * node)1495c2c66affSColin Finck static HRESULT build_directplay_tree(IDxDiagContainerImpl_Container *node)
1496c2c66affSColin Finck {
1497c2c66affSColin Finck     return S_OK;
1498c2c66affSColin Finck }
1499c2c66affSColin Finck 
build_systemdevices_tree(IDxDiagContainerImpl_Container * node)1500c2c66affSColin Finck static HRESULT build_systemdevices_tree(IDxDiagContainerImpl_Container *node)
1501c2c66affSColin Finck {
1502c2c66affSColin Finck     return S_OK;
1503c2c66affSColin Finck }
1504c2c66affSColin Finck 
fill_file_description(IDxDiagContainerImpl_Container * node,const WCHAR * szFilePath,const WCHAR * szFileName)1505c2c66affSColin Finck static HRESULT fill_file_description(IDxDiagContainerImpl_Container *node, const WCHAR *szFilePath, const WCHAR *szFileName)
1506c2c66affSColin Finck {
1507c2c66affSColin Finck     static const WCHAR szSlashSep[] = {'\\',0};
1508c2c66affSColin Finck     static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
1509c2c66affSColin Finck     static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1510c2c66affSColin Finck     static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
1511c2c66affSColin Finck     static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
1512c2c66affSColin Finck     static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
1513c2c66affSColin Finck     static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
1514c2c66affSColin Finck     static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
1515c2c66affSColin Finck     static const WCHAR bBeta[] = {'b','B','e','t','a',0};
1516c2c66affSColin Finck     static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
1517c2c66affSColin Finck     static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
1518c2c66affSColin Finck 
1519c2c66affSColin Finck     /* Values */
1520c2c66affSColin Finck     static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
1521c2c66affSColin Finck     static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
1522c2c66affSColin Finck     static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
1523c2c66affSColin Finck 
1524c2c66affSColin Finck     HRESULT hr;
1525c2c66affSColin Finck     WCHAR *szFile;
1526c2c66affSColin Finck     WCHAR szVersion_v[1024];
1527c2c66affSColin Finck     DWORD retval, hdl;
1528c2c66affSColin Finck     void *pVersionInfo = NULL;
1529c2c66affSColin Finck     BOOL boolret = FALSE;
1530c2c66affSColin Finck     UINT uiLength;
1531c2c66affSColin Finck     VS_FIXEDFILEINFO *pFileInfo;
1532c2c66affSColin Finck 
1533c2c66affSColin Finck     TRACE("Filling container %p for %s in %s\n", node,
1534c2c66affSColin Finck           debugstr_w(szFileName), debugstr_w(szFilePath));
1535c2c66affSColin Finck 
1536c2c66affSColin Finck     szFile = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(szFilePath) +
1537c2c66affSColin Finck                                             lstrlenW(szFileName) + 2 /* slash + terminator */));
1538c2c66affSColin Finck     if (!szFile)
1539c2c66affSColin Finck         return E_OUTOFMEMORY;
1540c2c66affSColin Finck 
1541c2c66affSColin Finck     lstrcpyW(szFile, szFilePath);
1542c2c66affSColin Finck     lstrcatW(szFile, szSlashSep);
1543c2c66affSColin Finck     lstrcatW(szFile, szFileName);
1544c2c66affSColin Finck 
1545c2c66affSColin Finck     retval = GetFileVersionInfoSizeW(szFile, &hdl);
1546c2c66affSColin Finck     if (retval)
1547c2c66affSColin Finck     {
1548c2c66affSColin Finck         pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
1549c2c66affSColin Finck         if (!pVersionInfo)
1550c2c66affSColin Finck         {
1551c2c66affSColin Finck             hr = E_OUTOFMEMORY;
1552c2c66affSColin Finck             goto cleanup;
1553c2c66affSColin Finck         }
1554c2c66affSColin Finck 
1555c2c66affSColin Finck         if (GetFileVersionInfoW(szFile, 0, retval, pVersionInfo) &&
1556c2c66affSColin Finck             VerQueryValueW(pVersionInfo, szSlashSep, (void **)&pFileInfo, &uiLength))
1557c2c66affSColin Finck             boolret = TRUE;
1558c2c66affSColin Finck     }
1559c2c66affSColin Finck 
1560c2c66affSColin Finck     hr = add_bstr_property(node, szPath, szFile);
1561c2c66affSColin Finck     if (FAILED(hr))
1562c2c66affSColin Finck         goto cleanup;
1563c2c66affSColin Finck 
1564c2c66affSColin Finck     hr = add_bstr_property(node, szName, szFileName);
1565c2c66affSColin Finck     if (FAILED(hr))
1566c2c66affSColin Finck         goto cleanup;
1567c2c66affSColin Finck 
1568c2c66affSColin Finck     hr = add_bool_property(node, bExists, boolret);
1569c2c66affSColin Finck     if (FAILED(hr))
1570c2c66affSColin Finck         goto cleanup;
1571c2c66affSColin Finck 
1572c2c66affSColin Finck     if (boolret)
1573c2c66affSColin Finck     {
1574*d6c879a0SAmine Khaldi         swprintf(szVersion_v, szVersionFormat,
1575*d6c879a0SAmine Khaldi                   HIWORD(pFileInfo->dwFileVersionMS), LOWORD(pFileInfo->dwFileVersionMS),
1576*d6c879a0SAmine Khaldi                   HIWORD(pFileInfo->dwFileVersionLS), LOWORD(pFileInfo->dwFileVersionLS));
1577c2c66affSColin Finck 
1578c2c66affSColin Finck         TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
1579c2c66affSColin Finck 
1580c2c66affSColin Finck         hr = add_bstr_property(node, szVersion, szVersion_v);
1581c2c66affSColin Finck         if (FAILED(hr))
1582c2c66affSColin Finck             goto cleanup;
1583c2c66affSColin Finck 
1584c2c66affSColin Finck         hr = add_bstr_property(node, szAttributes, szFinal_Retail_v);
1585c2c66affSColin Finck         if (FAILED(hr))
1586c2c66affSColin Finck             goto cleanup;
1587c2c66affSColin Finck 
1588c2c66affSColin Finck         hr = add_bstr_property(node, szLanguageEnglish, szEnglish_v);
1589c2c66affSColin Finck         if (FAILED(hr))
1590c2c66affSColin Finck             goto cleanup;
1591c2c66affSColin Finck 
1592c2c66affSColin Finck         hr = add_ui4_property(node, dwFileTimeHigh, pFileInfo->dwFileDateMS);
1593c2c66affSColin Finck         if (FAILED(hr))
1594c2c66affSColin Finck             goto cleanup;
1595c2c66affSColin Finck 
1596c2c66affSColin Finck         hr = add_ui4_property(node, dwFileTimeLow, pFileInfo->dwFileDateLS);
1597c2c66affSColin Finck         if (FAILED(hr))
1598c2c66affSColin Finck             goto cleanup;
1599c2c66affSColin Finck 
1600c2c66affSColin Finck         hr = add_bool_property(node, bBeta, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE) != 0);
1601c2c66affSColin Finck         if (FAILED(hr))
1602c2c66affSColin Finck             goto cleanup;
1603c2c66affSColin Finck 
1604c2c66affSColin Finck         hr = add_bool_property(node, bDebug, ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG) != 0);
1605c2c66affSColin Finck         if (FAILED(hr))
1606c2c66affSColin Finck             goto cleanup;
1607c2c66affSColin Finck     }
1608c2c66affSColin Finck 
1609c2c66affSColin Finck     hr = S_OK;
1610c2c66affSColin Finck cleanup:
1611c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, pVersionInfo);
1612c2c66affSColin Finck     HeapFree(GetProcessHeap(), 0, szFile);
1613c2c66affSColin Finck 
1614c2c66affSColin Finck     return hr;
1615c2c66affSColin Finck }
build_directxfiles_tree(IDxDiagContainerImpl_Container * node)1616c2c66affSColin Finck static HRESULT build_directxfiles_tree(IDxDiagContainerImpl_Container *node)
1617c2c66affSColin Finck {
1618c2c66affSColin Finck     static const WCHAR dlls[][15] =
1619c2c66affSColin Finck     {
1620c2c66affSColin Finck         {'d','3','d','8','.','d','l','l',0},
1621c2c66affSColin Finck         {'d','3','d','9','.','d','l','l',0},
1622c2c66affSColin Finck         {'d','d','r','a','w','.','d','l','l',0},
1623c2c66affSColin Finck         {'d','e','v','e','n','u','m','.','d','l','l',0},
1624c2c66affSColin Finck         {'d','i','n','p','u','t','8','.','d','l','l',0},
1625c2c66affSColin Finck         {'d','i','n','p','u','t','.','d','l','l',0},
1626c2c66affSColin Finck         {'d','m','b','a','n','d','.','d','l','l',0},
1627c2c66affSColin Finck         {'d','m','c','o','m','p','o','s','.','d','l','l',0},
1628c2c66affSColin Finck         {'d','m','i','m','e','.','d','l','l',0},
1629c2c66affSColin Finck         {'d','m','l','o','a','d','e','r','.','d','l','l',0},
1630c2c66affSColin Finck         {'d','m','s','c','r','i','p','t','.','d','l','l',0},
1631c2c66affSColin Finck         {'d','m','s','t','y','l','e','.','d','l','l',0},
1632c2c66affSColin Finck         {'d','m','s','y','n','t','h','.','d','l','l',0},
1633c2c66affSColin Finck         {'d','m','u','s','i','c','.','d','l','l',0},
1634c2c66affSColin Finck         {'d','p','l','a','y','x','.','d','l','l',0},
1635c2c66affSColin Finck         {'d','p','n','e','t','.','d','l','l',0},
1636c2c66affSColin Finck         {'d','s','o','u','n','d','.','d','l','l',0},
1637c2c66affSColin Finck         {'d','s','w','a','v','e','.','d','l','l',0},
1638c2c66affSColin Finck         {'d','x','d','i','a','g','n','.','d','l','l',0},
1639c2c66affSColin Finck         {'q','u','a','r','t','z','.','d','l','l',0}
1640c2c66affSColin Finck     };
1641c2c66affSColin Finck 
1642c2c66affSColin Finck     HRESULT hr;
1643c2c66affSColin Finck     WCHAR szFilePath[MAX_PATH];
1644c2c66affSColin Finck     INT i;
1645c2c66affSColin Finck 
1646c2c66affSColin Finck     GetSystemDirectoryW(szFilePath, MAX_PATH);
1647c2c66affSColin Finck 
1648*d6c879a0SAmine Khaldi     for (i = 0; i < ARRAY_SIZE(dlls); i++)
1649c2c66affSColin Finck     {
1650c2c66affSColin Finck         static const WCHAR szFormat[] = {'%','d',0};
1651c2c66affSColin Finck 
1652c2c66affSColin Finck         WCHAR szFileID[5];
1653c2c66affSColin Finck         IDxDiagContainerImpl_Container *file_container;
1654c2c66affSColin Finck 
1655*d6c879a0SAmine Khaldi         swprintf(szFileID, szFormat, i);
1656c2c66affSColin Finck 
1657c2c66affSColin Finck         file_container = allocate_information_node(szFileID);
1658c2c66affSColin Finck         if (!file_container)
1659c2c66affSColin Finck             return E_OUTOFMEMORY;
1660c2c66affSColin Finck 
1661c2c66affSColin Finck         hr = fill_file_description(file_container, szFilePath, dlls[i]);
1662c2c66affSColin Finck         if (FAILED(hr))
1663c2c66affSColin Finck         {
1664c2c66affSColin Finck             free_information_tree(file_container);
1665c2c66affSColin Finck             continue;
1666c2c66affSColin Finck         }
1667c2c66affSColin Finck 
1668c2c66affSColin Finck         add_subcontainer(node, file_container);
1669c2c66affSColin Finck     }
1670c2c66affSColin Finck 
1671c2c66affSColin Finck     return S_OK;
1672c2c66affSColin Finck }
1673c2c66affSColin Finck 
read_property_names(IPropertyBag * pPropBag,VARIANT * friendly_name,VARIANT * clsid_name)1674c2c66affSColin Finck static HRESULT read_property_names(IPropertyBag *pPropBag, VARIANT *friendly_name, VARIANT *clsid_name)
1675c2c66affSColin Finck {
1676c2c66affSColin Finck     static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
1677c2c66affSColin Finck     static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
1678c2c66affSColin Finck 
1679c2c66affSColin Finck     HRESULT hr;
1680c2c66affSColin Finck 
1681c2c66affSColin Finck     VariantInit(friendly_name);
1682c2c66affSColin Finck     VariantInit(clsid_name);
1683c2c66affSColin Finck 
1684c2c66affSColin Finck     hr = IPropertyBag_Read(pPropBag, wszFriendlyName, friendly_name, 0);
1685c2c66affSColin Finck     if (FAILED(hr))
1686c2c66affSColin Finck         return hr;
1687c2c66affSColin Finck 
1688c2c66affSColin Finck     hr = IPropertyBag_Read(pPropBag, wszClsidName, clsid_name, 0);
1689c2c66affSColin Finck     if (FAILED(hr))
1690c2c66affSColin Finck     {
1691c2c66affSColin Finck         VariantClear(friendly_name);
1692c2c66affSColin Finck         return hr;
1693c2c66affSColin Finck     }
1694c2c66affSColin Finck 
1695c2c66affSColin Finck     return S_OK;
1696c2c66affSColin Finck }
1697c2c66affSColin Finck 
fill_filter_data_information(IDxDiagContainerImpl_Container * subcont,BYTE * pData,ULONG cb)1698c2c66affSColin Finck static HRESULT fill_filter_data_information(IDxDiagContainerImpl_Container *subcont, BYTE *pData, ULONG cb)
1699c2c66affSColin Finck {
1700c2c66affSColin Finck     static const WCHAR szVersionW[] = {'s','z','V','e','r','s','i','o','n',0};
1701c2c66affSColin Finck     static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
1702c2c66affSColin Finck     static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
1703c2c66affSColin Finck     static const WCHAR dwMeritW[] = {'d','w','M','e','r','i','t',0};
1704c2c66affSColin Finck     static const WCHAR szVersionFormat[] = {'v','%','d',0};
1705c2c66affSColin Finck 
1706c2c66affSColin Finck     HRESULT hr;
1707c2c66affSColin Finck     IFilterMapper2 *pFileMapper = NULL;
1708c2c66affSColin Finck     IAMFilterData *pFilterData = NULL;
1709c2c66affSColin Finck     BYTE *ppRF = NULL;
1710c2c66affSColin Finck     REGFILTER2 *pRF = NULL;
1711c2c66affSColin Finck     WCHAR bufferW[10];
1712c2c66affSColin Finck     ULONG j;
1713c2c66affSColin Finck     DWORD dwNOutputs = 0;
1714c2c66affSColin Finck     DWORD dwNInputs = 0;
1715c2c66affSColin Finck 
1716c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC, &IID_IFilterMapper2,
1717c2c66affSColin Finck                           (void **)&pFileMapper);
1718c2c66affSColin Finck     if (FAILED(hr))
1719c2c66affSColin Finck         return hr;
1720c2c66affSColin Finck 
1721c2c66affSColin Finck     hr = IFilterMapper2_QueryInterface(pFileMapper, &IID_IAMFilterData, (void **)&pFilterData);
1722c2c66affSColin Finck     if (FAILED(hr))
1723c2c66affSColin Finck         goto cleanup;
1724c2c66affSColin Finck 
1725*d6c879a0SAmine Khaldi     hr = IAMFilterData_ParseFilterData(pFilterData, pData, cb, &ppRF);
1726c2c66affSColin Finck     if (FAILED(hr))
1727c2c66affSColin Finck         goto cleanup;
1728c2c66affSColin Finck     pRF = ((REGFILTER2**)ppRF)[0];
1729c2c66affSColin Finck 
1730*d6c879a0SAmine Khaldi     swprintf(bufferW, szVersionFormat, pRF->dwVersion);
1731c2c66affSColin Finck     hr = add_bstr_property(subcont, szVersionW, bufferW);
1732c2c66affSColin Finck     if (FAILED(hr))
1733c2c66affSColin Finck         goto cleanup;
1734c2c66affSColin Finck 
1735c2c66affSColin Finck     if (pRF->dwVersion == 1)
1736c2c66affSColin Finck     {
1737c2c66affSColin Finck         for (j = 0; j < pRF->u.s1.cPins; j++)
1738c2c66affSColin Finck             if (pRF->u.s1.rgPins[j].bOutput)
1739c2c66affSColin Finck                 dwNOutputs++;
1740c2c66affSColin Finck             else
1741c2c66affSColin Finck                 dwNInputs++;
1742c2c66affSColin Finck     }
1743c2c66affSColin Finck     else if (pRF->dwVersion == 2)
1744c2c66affSColin Finck     {
1745c2c66affSColin Finck         for (j = 0; j < pRF->u.s2.cPins2; j++)
1746c2c66affSColin Finck             if (pRF->u.s2.rgPins2[j].dwFlags & REG_PINFLAG_B_OUTPUT)
1747c2c66affSColin Finck                 dwNOutputs++;
1748c2c66affSColin Finck             else
1749c2c66affSColin Finck                 dwNInputs++;
1750c2c66affSColin Finck     }
1751c2c66affSColin Finck 
1752c2c66affSColin Finck     hr = add_ui4_property(subcont, dwInputs, dwNInputs);
1753c2c66affSColin Finck     if (FAILED(hr))
1754c2c66affSColin Finck         goto cleanup;
1755c2c66affSColin Finck 
1756c2c66affSColin Finck     hr = add_ui4_property(subcont, dwOutputs, dwNOutputs);
1757c2c66affSColin Finck     if (FAILED(hr))
1758c2c66affSColin Finck         goto cleanup;
1759c2c66affSColin Finck 
1760c2c66affSColin Finck     hr = add_ui4_property(subcont, dwMeritW, pRF->dwMerit);
1761c2c66affSColin Finck     if (FAILED(hr))
1762c2c66affSColin Finck         goto cleanup;
1763c2c66affSColin Finck 
1764c2c66affSColin Finck     hr = S_OK;
1765c2c66affSColin Finck cleanup:
1766c2c66affSColin Finck     CoTaskMemFree(pRF);
1767c2c66affSColin Finck     if (pFilterData) IAMFilterData_Release(pFilterData);
1768c2c66affSColin Finck     if (pFileMapper) IFilterMapper2_Release(pFileMapper);
1769c2c66affSColin Finck 
1770c2c66affSColin Finck     return hr;
1771c2c66affSColin Finck }
1772c2c66affSColin Finck 
fill_filter_container(IDxDiagContainerImpl_Container * subcont,IMoniker * pMoniker)1773c2c66affSColin Finck static HRESULT fill_filter_container(IDxDiagContainerImpl_Container *subcont, IMoniker *pMoniker)
1774c2c66affSColin Finck {
1775c2c66affSColin Finck     static const WCHAR szName[] = {'s','z','N','a','m','e',0};
1776c2c66affSColin Finck     static const WCHAR ClsidFilterW[] = {'C','l','s','i','d','F','i','l','t','e','r',0};
1777c2c66affSColin Finck     static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
1778c2c66affSColin Finck 
1779c2c66affSColin Finck     HRESULT hr;
1780c2c66affSColin Finck     IPropertyBag *pPropFilterBag = NULL;
1781c2c66affSColin Finck     BYTE *pData;
1782c2c66affSColin Finck     VARIANT friendly_name;
1783c2c66affSColin Finck     VARIANT clsid_name;
1784c2c66affSColin Finck     VARIANT v;
1785c2c66affSColin Finck 
1786c2c66affSColin Finck     VariantInit(&friendly_name);
1787c2c66affSColin Finck     VariantInit(&clsid_name);
1788c2c66affSColin Finck     VariantInit(&v);
1789c2c66affSColin Finck 
1790c2c66affSColin Finck     hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void **)&pPropFilterBag);
1791c2c66affSColin Finck     if (FAILED(hr))
1792c2c66affSColin Finck         return hr;
1793c2c66affSColin Finck 
1794c2c66affSColin Finck     hr = read_property_names(pPropFilterBag, &friendly_name, &clsid_name);
1795c2c66affSColin Finck     if (FAILED(hr))
1796c2c66affSColin Finck         goto cleanup;
1797c2c66affSColin Finck 
1798c2c66affSColin Finck     TRACE("Name = %s\n", debugstr_w(V_BSTR(&friendly_name)));
1799c2c66affSColin Finck     TRACE("CLSID = %s\n", debugstr_w(V_BSTR(&clsid_name)));
1800c2c66affSColin Finck 
1801c2c66affSColin Finck     hr = add_bstr_property(subcont, szName, V_BSTR(&friendly_name));
1802c2c66affSColin Finck     if (FAILED(hr))
1803c2c66affSColin Finck         goto cleanup;
1804c2c66affSColin Finck 
1805c2c66affSColin Finck     hr = add_bstr_property(subcont, ClsidFilterW, V_BSTR(&clsid_name));
1806c2c66affSColin Finck     if (FAILED(hr))
1807c2c66affSColin Finck         goto cleanup;
1808c2c66affSColin Finck 
1809c2c66affSColin Finck     hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
1810c2c66affSColin Finck     if (FAILED(hr))
1811c2c66affSColin Finck         goto cleanup;
1812c2c66affSColin Finck 
1813c2c66affSColin Finck     hr = SafeArrayAccessData(V_ARRAY(&v), (void **)&pData);
1814c2c66affSColin Finck     if (FAILED(hr))
1815c2c66affSColin Finck         goto cleanup;
1816c2c66affSColin Finck 
1817c2c66affSColin Finck     hr = fill_filter_data_information(subcont, pData, V_ARRAY(&v)->rgsabound->cElements);
1818c2c66affSColin Finck     SafeArrayUnaccessData(V_ARRAY(&v));
1819c2c66affSColin Finck     if (FAILED(hr))
1820c2c66affSColin Finck         goto cleanup;
1821c2c66affSColin Finck 
1822c2c66affSColin Finck     hr = S_OK;
1823c2c66affSColin Finck cleanup:
1824c2c66affSColin Finck     VariantClear(&v);
1825c2c66affSColin Finck     VariantClear(&clsid_name);
1826c2c66affSColin Finck     VariantClear(&friendly_name);
1827c2c66affSColin Finck     if (pPropFilterBag) IPropertyBag_Release(pPropFilterBag);
1828c2c66affSColin Finck 
1829c2c66affSColin Finck     return hr;
1830c2c66affSColin Finck }
1831c2c66affSColin Finck 
build_directshowfilters_tree(IDxDiagContainerImpl_Container * node)1832c2c66affSColin Finck static HRESULT build_directshowfilters_tree(IDxDiagContainerImpl_Container *node)
1833c2c66affSColin Finck {
1834c2c66affSColin Finck     static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
1835c2c66affSColin Finck     static const WCHAR ClsidCatW[] = {'C','l','s','i','d','C','a','t',0};
1836c2c66affSColin Finck     static const WCHAR szIdFormat[] = {'%','d',0};
1837c2c66affSColin Finck 
1838c2c66affSColin Finck     HRESULT hr;
1839c2c66affSColin Finck     int i = 0;
1840c2c66affSColin Finck     ICreateDevEnum *pCreateDevEnum;
1841c2c66affSColin Finck     IEnumMoniker *pEmCat = NULL;
1842c2c66affSColin Finck     IMoniker *pMCat = NULL;
1843c2c66affSColin Finck 	IEnumMoniker *pEnum = NULL;
1844c2c66affSColin Finck 
1845c2c66affSColin Finck     hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
1846c2c66affSColin Finck                           &IID_ICreateDevEnum, (void **)&pCreateDevEnum);
1847c2c66affSColin Finck     if (FAILED(hr))
1848c2c66affSColin Finck         return hr;
1849c2c66affSColin Finck 
1850c2c66affSColin Finck     hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
1851c2c66affSColin Finck     if (FAILED(hr))
1852c2c66affSColin Finck         goto cleanup;
1853c2c66affSColin Finck 
1854c2c66affSColin Finck     while (IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL) == S_OK)
1855c2c66affSColin Finck     {
1856c2c66affSColin Finck         VARIANT vCatName;
1857c2c66affSColin Finck         VARIANT vCatClsid;
1858c2c66affSColin Finck         IPropertyBag *pPropBag;
1859c2c66affSColin Finck         CLSID clsidCat;
1860c2c66affSColin Finck         IMoniker *pMoniker = NULL;
1861c2c66affSColin Finck 
1862c2c66affSColin Finck         hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void **)&pPropBag);
1863c2c66affSColin Finck         if (FAILED(hr))
1864c2c66affSColin Finck         {
1865c2c66affSColin Finck             IMoniker_Release(pMCat);
1866c2c66affSColin Finck             break;
1867c2c66affSColin Finck         }
1868c2c66affSColin Finck 
1869c2c66affSColin Finck         hr = read_property_names(pPropBag, &vCatName, &vCatClsid);
1870c2c66affSColin Finck         IPropertyBag_Release(pPropBag);
1871c2c66affSColin Finck         if (FAILED(hr))
1872c2c66affSColin Finck         {
1873c2c66affSColin Finck             IMoniker_Release(pMCat);
1874c2c66affSColin Finck             break;
1875c2c66affSColin Finck         }
1876c2c66affSColin Finck 
1877c2c66affSColin Finck         hr = CLSIDFromString(V_BSTR(&vCatClsid), &clsidCat);
1878c2c66affSColin Finck         if (FAILED(hr))
1879c2c66affSColin Finck         {
1880c2c66affSColin Finck             IMoniker_Release(pMCat);
1881c2c66affSColin Finck             VariantClear(&vCatClsid);
1882c2c66affSColin Finck             VariantClear(&vCatName);
1883c2c66affSColin Finck             break;
1884c2c66affSColin Finck         }
1885c2c66affSColin Finck 
1886c2c66affSColin Finck         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1887c2c66affSColin Finck         if (hr != S_OK)
1888c2c66affSColin Finck         {
1889c2c66affSColin Finck             IMoniker_Release(pMCat);
1890c2c66affSColin Finck             VariantClear(&vCatClsid);
1891c2c66affSColin Finck             VariantClear(&vCatName);
1892c2c66affSColin Finck             continue;
1893c2c66affSColin Finck         }
1894c2c66affSColin Finck 
1895c2c66affSColin Finck         TRACE("Enumerating class %s\n", debugstr_guid(&clsidCat));
1896c2c66affSColin Finck 
1897c2c66affSColin Finck         while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1898c2c66affSColin Finck         {
1899c2c66affSColin Finck             WCHAR bufferW[10];
1900c2c66affSColin Finck             IDxDiagContainerImpl_Container *subcont;
1901c2c66affSColin Finck 
1902*d6c879a0SAmine Khaldi             swprintf(bufferW, szIdFormat, i);
1903c2c66affSColin Finck             subcont = allocate_information_node(bufferW);
1904c2c66affSColin Finck             if (!subcont)
1905c2c66affSColin Finck             {
1906c2c66affSColin Finck                 hr = E_OUTOFMEMORY;
1907c2c66affSColin Finck                 IMoniker_Release(pMoniker);
1908c2c66affSColin Finck                 break;
1909c2c66affSColin Finck             }
1910c2c66affSColin Finck 
1911c2c66affSColin Finck             hr = add_bstr_property(subcont, szCatName, V_BSTR(&vCatName));
1912c2c66affSColin Finck             if (FAILED(hr))
1913c2c66affSColin Finck             {
1914c2c66affSColin Finck                 free_information_tree(subcont);
1915c2c66affSColin Finck                 IMoniker_Release(pMoniker);
1916c2c66affSColin Finck                 break;
1917c2c66affSColin Finck             }
1918c2c66affSColin Finck 
1919c2c66affSColin Finck             hr = add_bstr_property(subcont, ClsidCatW, V_BSTR(&vCatClsid));
1920c2c66affSColin Finck             if (FAILED(hr))
1921c2c66affSColin Finck             {
1922c2c66affSColin Finck                 free_information_tree(subcont);
1923c2c66affSColin Finck                 IMoniker_Release(pMoniker);
1924c2c66affSColin Finck                 break;
1925c2c66affSColin Finck             }
1926c2c66affSColin Finck 
1927c2c66affSColin Finck             hr = fill_filter_container(subcont, pMoniker);
1928c2c66affSColin Finck             IMoniker_Release(pMoniker);
1929c2c66affSColin Finck             if (FAILED(hr))
1930c2c66affSColin Finck             {
1931c2c66affSColin Finck                 WARN("Skipping invalid filter\n");
1932c2c66affSColin Finck                 free_information_tree(subcont);
1933c2c66affSColin Finck                 hr = S_OK;
1934c2c66affSColin Finck                 continue;
1935c2c66affSColin Finck             }
1936c2c66affSColin Finck 
1937c2c66affSColin Finck             add_subcontainer(node, subcont);
1938c2c66affSColin Finck             i++;
1939c2c66affSColin Finck         }
1940c2c66affSColin Finck 
1941c2c66affSColin Finck         IEnumMoniker_Release(pEnum);
1942c2c66affSColin Finck         IMoniker_Release(pMCat);
1943c2c66affSColin Finck         VariantClear(&vCatClsid);
1944c2c66affSColin Finck         VariantClear(&vCatName);
1945c2c66affSColin Finck 
1946c2c66affSColin Finck         if (FAILED(hr))
1947c2c66affSColin Finck             break;
1948c2c66affSColin Finck     }
1949c2c66affSColin Finck 
1950c2c66affSColin Finck cleanup:
1951c2c66affSColin Finck     if (pEmCat) IEnumMoniker_Release(pEmCat);
1952c2c66affSColin Finck     ICreateDevEnum_Release(pCreateDevEnum);
1953c2c66affSColin Finck     return hr;
1954c2c66affSColin Finck }
1955c2c66affSColin Finck 
build_logicaldisks_tree(IDxDiagContainerImpl_Container * node)1956c2c66affSColin Finck static HRESULT build_logicaldisks_tree(IDxDiagContainerImpl_Container *node)
1957c2c66affSColin Finck {
1958c2c66affSColin Finck     return S_OK;
1959c2c66affSColin Finck }
1960c2c66affSColin Finck 
build_information_tree(IDxDiagContainerImpl_Container ** pinfo_root)1961c2c66affSColin Finck static HRESULT build_information_tree(IDxDiagContainerImpl_Container **pinfo_root)
1962c2c66affSColin Finck {
1963c2c66affSColin Finck     static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
1964c2c66affSColin Finck     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};
1965c2c66affSColin Finck     static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
1966c2c66affSColin Finck     static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
1967c2c66affSColin Finck     static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
1968c2c66affSColin Finck     static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
1969c2c66affSColin Finck     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};
1970c2c66affSColin Finck     static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
1971c2c66affSColin Finck     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};
1972c2c66affSColin Finck     static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
1973c2c66affSColin Finck 
1974c2c66affSColin Finck     static const struct
1975c2c66affSColin Finck     {
1976c2c66affSColin Finck         const WCHAR *name;
1977c2c66affSColin Finck         HRESULT (*initfunc)(IDxDiagContainerImpl_Container *);
1978c2c66affSColin Finck     } root_children[] =
1979c2c66affSColin Finck     {
1980c2c66affSColin Finck         {DxDiag_SystemInfo, build_systeminfo_tree},
1981c2c66affSColin Finck         {DxDiag_DisplayDevices, build_displaydevices_tree},
1982c2c66affSColin Finck         {DxDiag_DirectSound, build_directsound_tree},
1983c2c66affSColin Finck         {DxDiag_DirectMusic, build_directmusic_tree},
1984c2c66affSColin Finck         {DxDiag_DirectInput, build_directinput_tree},
1985c2c66affSColin Finck         {DxDiag_DirectPlay, build_directplay_tree},
1986c2c66affSColin Finck         {DxDiag_SystemDevices, build_systemdevices_tree},
1987c2c66affSColin Finck         {DxDiag_DirectXFiles, build_directxfiles_tree},
1988c2c66affSColin Finck         {DxDiag_DirectShowFilters, build_directshowfilters_tree},
1989c2c66affSColin Finck         {DxDiag_LogicalDisks, build_logicaldisks_tree},
1990c2c66affSColin Finck     };
1991c2c66affSColin Finck 
1992c2c66affSColin Finck     IDxDiagContainerImpl_Container *info_root;
1993c2c66affSColin Finck     size_t index;
1994c2c66affSColin Finck 
1995c2c66affSColin Finck     info_root = allocate_information_node(NULL);
1996c2c66affSColin Finck     if (!info_root)
1997c2c66affSColin Finck         return E_OUTOFMEMORY;
1998c2c66affSColin Finck 
1999*d6c879a0SAmine Khaldi     for (index = 0; index < ARRAY_SIZE(root_children); index++)
2000c2c66affSColin Finck     {
2001c2c66affSColin Finck         IDxDiagContainerImpl_Container *node;
2002c2c66affSColin Finck         HRESULT hr;
2003c2c66affSColin Finck 
2004c2c66affSColin Finck         node = allocate_information_node(root_children[index].name);
2005c2c66affSColin Finck         if (!node)
2006c2c66affSColin Finck         {
2007c2c66affSColin Finck             free_information_tree(info_root);
2008c2c66affSColin Finck             return E_OUTOFMEMORY;
2009c2c66affSColin Finck         }
2010c2c66affSColin Finck 
2011c2c66affSColin Finck         hr = root_children[index].initfunc(node);
2012c2c66affSColin Finck         if (FAILED(hr))
2013c2c66affSColin Finck         {
2014c2c66affSColin Finck             free_information_tree(node);
2015c2c66affSColin Finck             free_information_tree(info_root);
2016c2c66affSColin Finck             return hr;
2017c2c66affSColin Finck         }
2018c2c66affSColin Finck 
2019c2c66affSColin Finck         add_subcontainer(info_root, node);
2020c2c66affSColin Finck     }
2021c2c66affSColin Finck 
2022c2c66affSColin Finck     *pinfo_root = info_root;
2023c2c66affSColin Finck     return S_OK;
2024c2c66affSColin Finck }
2025