serialui: Convert Japanese resource to UTF-8.
[wine] / dlls / dxdiagn / provider.c
1 /* 
2  * IDxDiagProvider Implementation
3  * 
4  * Copyright 2004-2005 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #include "config.h"
23
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #include "dxdiag_private.h"
27 #include "wine/unicode.h"
28 #include "winver.h"
29 #include "objidl.h"
30 #include "dshow.h"
31 #include "strmif.h"
32 #include "vfw.h"
33 #include "mmddk.h"
34 #include "ddraw.h"
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
39
40 /* IDxDiagProvider IUnknown parts follow: */
41 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
42 {
43     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
44
45     if (IsEqualGUID(riid, &IID_IUnknown)
46         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
47         IUnknown_AddRef(iface);
48         *ppobj = This;
49         return S_OK;
50     }
51
52     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
53     return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
57     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
58     ULONG refCount = InterlockedIncrement(&This->ref);
59
60     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
61
62     DXDIAGN_LockModule();
63
64     return refCount;
65 }
66
67 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
68     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
69     ULONG refCount = InterlockedDecrement(&This->ref);
70
71     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
72
73     if (!refCount) {
74         HeapFree(GetProcessHeap(), 0, This);
75     }
76
77     DXDIAGN_UnlockModule();
78     
79     return refCount;
80 }
81
82 /* IDxDiagProvider Interface follow: */
83 static HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
84     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
85     TRACE("(%p,%p)\n", iface, pParams);
86
87     if (NULL == pParams) {
88       return E_POINTER;
89     }
90     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
91       return E_INVALIDARG;
92     }
93
94     This->init = TRUE;
95     memcpy(&This->params, pParams, pParams->dwSize);
96     return S_OK;
97 }
98
99 static HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
100   HRESULT hr = S_OK;
101   IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
102   TRACE("(%p,%p)\n", iface, ppInstance);
103
104   if (NULL == ppInstance) {
105     return E_INVALIDARG;
106   }
107   if (FALSE == This->init) {
108     return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
109   }
110   if (NULL == This->pRootContainer) {
111     hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
112     if (FAILED(hr)) {
113       return hr;
114     }
115     hr = DXDiag_InitRootDXDiagContainer(This->pRootContainer);
116   }
117   return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
118 }
119
120 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
121 {
122     IDxDiagProviderImpl_QueryInterface,
123     IDxDiagProviderImpl_AddRef,
124     IDxDiagProviderImpl_Release,
125     IDxDiagProviderImpl_Initialize,
126     IDxDiagProviderImpl_GetRootContainer
127 };
128
129 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
130   IDxDiagProviderImpl* provider;
131
132   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
133   
134   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
135   if (NULL == provider) {
136     *ppobj = NULL;
137     return E_OUTOFMEMORY;
138   }
139   provider->lpVtbl = &DxDiagProvider_Vtbl;
140   provider->ref = 0; /* will be inited with QueryInterface */
141   return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
142
143
144 static inline HRESULT add_prop_str( IDxDiagContainer* cont, LPCWSTR prop, LPCWSTR str )
145 {
146     HRESULT hr;
147     VARIANT var;
148
149     V_VT( &var ) = VT_BSTR;
150     V_BSTR( &var ) = SysAllocString( str );
151     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
152     VariantClear( &var );
153
154     return hr;
155 }
156
157 static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
158 {
159     VARIANT var;
160
161     V_VT( &var ) = VT_UI4;
162     V_UI4( &var ) = data;
163     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
164 }
165
166 static inline HRESULT add_prop_bool( IDxDiagContainer* cont, LPCWSTR prop, BOOL data )
167 {
168     VARIANT var;
169
170     V_VT( &var ) = VT_BOOL;
171     V_BOOL( &var ) = data;
172     return IDxDiagContainerImpl_AddProp( cont, prop, &var );
173 }
174
175 /**
176  * @param szFilePath: usually GetSystemDirectoryW
177  * @param szFileName: name of the dll without path
178  */
179 static HRESULT DXDiag_AddFileDescContainer(IDxDiagContainer* pSubCont, const WCHAR* szFilePath, const WCHAR* szFileName) {
180   HRESULT hr = S_OK;
181   /**/
182   static const WCHAR szSlashSep[] = {'\\',0};
183   static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
184   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
185   static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
186   static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
187   static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
188   static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
189   static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
190   static const WCHAR bBeta[] = {'b','B','e','t','a',0};
191   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
192   static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
193   /** values */
194   static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
195   static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
196   static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
197
198   WCHAR szFile[512];
199   WCHAR szVersion_v[1024];
200   DWORD retval, hdl;
201   LPVOID pVersionInfo;
202   BOOL boolret;
203   UINT uiLength;
204   VS_FIXEDFILEINFO* pFileInfo;
205
206   FIXME("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
207   
208   lstrcpyW(szFile, szFilePath);
209   lstrcatW(szFile, szSlashSep);
210   lstrcatW(szFile, szFileName);
211
212   retval = GetFileVersionInfoSizeW(szFile, &hdl);
213   pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
214   boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
215   boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
216
217   add_prop_str(pSubCont, szPath, szFile);
218   add_prop_str(pSubCont, szName, szFileName);
219   add_prop_bool(pSubCont, bExists, boolret);
220
221   if (boolret) {
222     snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
223               szVersionFormat,
224               HIWORD(pFileInfo->dwFileVersionMS), 
225               LOWORD(pFileInfo->dwFileVersionMS),
226               HIWORD(pFileInfo->dwFileVersionLS),
227               LOWORD(pFileInfo->dwFileVersionLS));
228
229     TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
230
231     add_prop_str(pSubCont, szVersion,         szVersion_v);
232     add_prop_str(pSubCont, szAttributes,      szFinal_Retail_v);
233     add_prop_str(pSubCont, szLanguageEnglish, szEnglish_v);
234     add_prop_ui4(pSubCont, dwFileTimeHigh,    pFileInfo->dwFileDateMS);
235     add_prop_ui4(pSubCont, dwFileTimeLow,     pFileInfo->dwFileDateLS);
236     add_prop_bool(pSubCont, bBeta,  0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE));
237     add_prop_bool(pSubCont, bDebug, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG));
238   }
239
240   HeapFree(GetProcessHeap(), 0, pVersionInfo);
241
242   return hr;
243 }
244
245 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
246   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};
247   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};
248   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};
249   static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
250   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
251   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};
252   static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
253   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};
254   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};
255   static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
256   /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
257   /*szWindowsDir*/
258   /*szWindowsDir*/
259   static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
260   static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
261   static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
262   static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
263   MEMORYSTATUSEX msex;
264   OSVERSIONINFOW info;
265   VARIANT v;
266
267   add_prop_ui4(pSubCont, dwDirectXVersionMajor, 9);
268   add_prop_ui4(pSubCont, dwDirectXVersionMinor, 0);
269   add_prop_str(pSubCont, szDirectXVersionLetter, szDirectXVersionLetter_v);
270   add_prop_str(pSubCont, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
271   add_prop_str(pSubCont, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
272   add_prop_bool(pSubCont, bDebug, FALSE);
273
274   msex.dwLength = sizeof(msex);
275   GlobalMemoryStatusEx( &msex );
276   V_VT(&v) = VT_UI8;
277   V_UI8(&v) = msex.ullTotalPhys;
278   VariantChangeType(&v, &v, 0, VT_BSTR);
279   IDxDiagContainerImpl_AddProp(pSubCont, ullPhysicalMemory, &v);
280   VariantClear(&v);
281
282   info.dwOSVersionInfoSize = sizeof(info);
283   GetVersionExW( &info );
284   add_prop_ui4(pSubCont, dwOSMajorVersion, info.dwMajorVersion);
285   add_prop_ui4(pSubCont, dwOSMinorVersion, info.dwMinorVersion);
286   add_prop_ui4(pSubCont, dwOSBuildNumber,  info.dwBuildNumber);
287   add_prop_ui4(pSubCont, dwOSPlatformID,   info.dwPlatformId);
288
289   return S_OK;
290 }
291
292 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
293   HRESULT hr = S_OK;
294   /*
295   static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
296   static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
297
298   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
299
300   VARIANT v;
301   IDxDiagContainer* pDeviceSubCont = NULL;
302   IDxDiagContainer* pDriversCont = NULL;
303
304   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDeviceSubCont);
305   if (FAILED(hr)) { return hr; }
306   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
307   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
308   VariantClear(&v);
309   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
310   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
311   VariantClear(&v);
312
313   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
314   */
315
316   /*
317    * Drivers Cont contains Files Desc Containers
318    */
319   /*
320   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
321   if (FAILED(hr)) { return hr; }
322   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
323
324   */
325   return hr;
326 }
327
328 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
329   HRESULT hr = S_OK;
330   /*
331   static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
332   static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
333   static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
334   static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
335   static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
336   static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
337   static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
338
339   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
340  
341   VARIANT v;
342   IDxDiagContainer* pDiskSubCont = NULL;
343   IDxDiagContainer* pDriversCont = NULL;
344
345   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDiskSubCont);
346   if (FAILED(hr)) { return hr; }
347   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
348   */
349   
350   /*
351    * Drivers Cont contains Files Desc Containers
352    */
353   /*
354   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
355   if (FAILED(hr)) { return hr; }
356   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
357   */
358   return hr;
359 }
360 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont) {
361   HRESULT hr = S_OK;
362   /**/
363   static const WCHAR ddraw_dll[] = {'d','d','r','a','w','.','d','l','l',0};
364   static const WCHAR dplayx_dll[] = {'d','p','l','a','y','x','.','d','l','l',0};
365   static const WCHAR dpnet_dll[] = {'d','p','n','e','t','.','d','l','l',0};
366   static const WCHAR dinput_dll[] = {'d','i','n','p','u','t','.','d','l','l',0};
367   static const WCHAR dinput8_dll[] = {'d','i','n','p','u','t','8','.','d','l','l',0};
368   static const WCHAR dsound_dll[] = {'d','s','o','u','n','d','.','d','l','l',0};
369   static const WCHAR dswave_dll[] = {'d','s','w','a','v','e','.','d','l','l',0};
370   static const WCHAR d3d8_dll[] = {'d','3','d','8','.','d','l','l',0};
371   static const WCHAR d3d9_dll[] = {'d','3','d','9','.','d','l','l',0};
372   static const WCHAR dmband_dll[] = {'d','m','b','a','n','d','.','d','l','l',0};
373   static const WCHAR dmcompos_dll[] = {'d','m','c','o','m','p','o','s','.','d','l','l',0};
374   static const WCHAR dmime_dll[] =  {'d','m','i','m','e','.','d','l','l',0};
375   static const WCHAR dmloader_dll[] = {'d','m','l','o','a','d','e','r','.','d','l','l',0};
376   static const WCHAR dmscript_dll[] = {'d','m','s','c','r','i','p','t','.','d','l','l',0};
377   static const WCHAR dmstyle_dll[] = {'d','m','s','t','y','l','e','.','d','l','l',0};
378   static const WCHAR dmsynth_dll[] = {'d','m','s','y','n','t','h','.','d','l','l',0};
379   static const WCHAR dmusic_dll[] = {'d','m','u','s','i','c','.','d','l','l',0};
380   static const WCHAR devenum_dll[] = {'d','e','v','e','n','u','m','.','d','l','l',0};
381   static const WCHAR quartz_dll[] = {'q','u','a','r','t','z','.','d','l','l',0};
382   WCHAR szFilePath[512];
383
384   hr = GetSystemDirectoryW(szFilePath, MAX_PATH);
385   if (FAILED(hr)) { return hr; }  
386   szFilePath[MAX_PATH-1]=0;     
387
388   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, ddraw_dll);
389   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dplayx_dll);
390   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dpnet_dll);
391   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput_dll);
392   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput8_dll);
393   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dsound_dll);
394   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dswave_dll);
395   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d8_dll);
396   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d9_dll);
397   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmband_dll);
398   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmcompos_dll);
399   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmime_dll);
400   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmloader_dll);
401   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmscript_dll);
402   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmstyle_dll);
403   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmsynth_dll);
404   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmusic_dll);
405   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, devenum_dll);
406   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, quartz_dll);
407   return hr;
408 }
409
410 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
411 {
412     static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
413     static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
414     static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
415     static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
416     static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
417     static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
418     static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
419     static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
420     static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
421     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};
422     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};
423
424     static const WCHAR szAdapterID[] = {'0',0};
425     static const WCHAR szEmpty[] = {0};
426
427     HRESULT                 hr;
428     IDxDiagContainer       *pDisplayAdapterSubCont = NULL;
429
430     IDirectDraw7           *pDirectDraw;
431     DDSCAPS2                dd_caps;
432     DISPLAY_DEVICEW         disp_dev;
433     DDSURFACEDESC2          surface_descr;
434     DWORD                   tmp;
435     WCHAR                   buffer[256];
436
437     hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
438     if (FAILED( hr )) return hr;
439     hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
440     if (FAILED( hr )) return hr;
441
442     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
443     {
444         add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
445         add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
446     }
447
448     hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
449     if (FAILED( hr )) return hr;
450
451     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
452     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
453     hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
454     if (SUCCEEDED(hr))
455     {
456         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
457
458         snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
459         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
460         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
461     }
462
463     surface_descr.dwSize = sizeof(surface_descr);
464     hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
465     if (SUCCEEDED(hr))
466     {
467         if (surface_descr.dwFlags & DDSD_WIDTH)
468             add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
469         if (surface_descr.dwFlags & DDSD_HEIGHT)
470             add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
471         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
472             add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
473     }
474
475     add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
476     add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
477     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
478     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
479
480     IUnknown_Release( pDirectDraw );
481     return hr;
482 }
483
484 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
485   HRESULT hr = S_OK;
486   static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
487   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};
488   IDxDiagContainer* pSubSubCont = NULL;
489
490   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
491   if (FAILED(hr)) { return hr; }
492   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
493
494   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
495   if (FAILED(hr)) { return hr; }
496   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
497
498   return hr;
499 }
500
501 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
502   HRESULT hr = S_OK;
503   return hr;
504 }
505
506 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
507   HRESULT hr = S_OK;
508   return hr;
509 }
510
511 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
512   HRESULT hr = S_OK;
513   return hr;
514 }
515
516 struct REG_RF {
517   DWORD dwVersion;
518   DWORD dwMerit;
519   DWORD dwPins;
520   DWORD dwUnused;
521 };
522 struct REG_RFP {
523   BYTE signature[4]; /* e.g. "0pi3" */
524   DWORD dwFlags;
525   DWORD dwInstances;
526   DWORD dwMediaTypes;
527   DWORD dwMediums;
528   DWORD bCategory; /* is there a category clsid? */
529   /* optional: dwOffsetCategoryClsid */
530 };
531 struct REG_TYPE {
532   BYTE signature[4]; /* e.g. "0ty3" */
533   DWORD dwUnused;
534   DWORD dwOffsetMajor;
535   DWORD dwOffsetMinor;
536 };
537
538 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
539   HRESULT hr = S_OK;
540   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
541   static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
542   static const WCHAR szClsidCat[] = {'s','z','C','l','s','i','d','C','a','t',0};
543   static const WCHAR szClsidFilter[] = {'s','z','C','l','s','i','d','F','i','l','t','e','r',0};
544   static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
545   static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
546   static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0};
547   /*
548   static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
549   static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
550   */
551   VARIANT v;
552
553   static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
554   static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};  
555   static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
556   /*static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};*/
557
558   ICreateDevEnum* pCreateDevEnum = NULL;
559   IEnumMoniker* pEmCat = NULL;
560   IMoniker* pMCat = NULL;
561   /** */
562   hr = CoCreateInstance(&CLSID_SystemDeviceEnum, 
563                         NULL, 
564                         CLSCTX_INPROC_SERVER,
565                         &IID_ICreateDevEnum, 
566                         (void**) &pCreateDevEnum);
567   if (FAILED(hr)) return hr; 
568   
569   hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
570   if (FAILED(hr)) goto out_show_filters; 
571
572   VariantInit(&v);
573
574   while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
575     IPropertyBag* pPropBag = NULL;
576     CLSID clsidCat; 
577     hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
578     if (SUCCEEDED(hr)) {
579       WCHAR* wszCatName = NULL;
580       WCHAR* wszCatClsid = NULL;
581
582       hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
583       wszCatName = SysAllocString(V_BSTR(&v));
584       VariantClear(&v);
585
586       hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
587       wszCatClsid = SysAllocString(V_BSTR(&v));
588       hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
589       VariantClear(&v);
590
591       /*
592       hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
593       hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
594       VariantClear(&v);
595       */
596
597       if (SUCCEEDED(hr)) {
598         IEnumMoniker* pEnum = NULL;
599         IMoniker* pMoniker = NULL;
600         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);        
601         FIXME("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
602         if (FAILED(hr) || pEnum == NULL) {
603           goto class_enum_failed;
604         }
605         while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {          
606           IPropertyBag* pPropFilterBag = NULL;
607           FIXME("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
608           hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
609           if (SUCCEEDED(hr)) {
610             LPBYTE pData = NULL;
611             LPBYTE pCurrent = NULL;
612             struct REG_RF* prrf = NULL;
613             DWORD it;
614             DWORD dwNOutputs = 0;
615             DWORD dwNInputs = 0;
616
617             add_prop_str(pSubCont, szCatName, wszCatName);
618             add_prop_str(pSubCont, szClsidCat, wszCatClsid);
619
620             hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
621             hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v);
622             FIXME("\tName:%s\n", debugstr_w(V_BSTR(&v)));
623             VariantClear(&v);
624
625             hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
626             FIXME("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
627             hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidFilter, &v);
628             VariantClear(&v);
629
630             hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
631             hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData);        
632             prrf = (struct REG_RF*) pData;
633             pCurrent = pData;
634
635             add_prop_ui4(pSubCont, szName, prrf->dwVersion);
636             add_prop_ui4(pSubCont, dwMerit, prrf->dwMerit);
637
638             pCurrent += sizeof(struct REG_RF);
639             for (it = 0; it < prrf->dwPins; ++it) {
640               struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent;
641               UINT j;
642
643               if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs;
644               else ++dwNInputs;
645
646               pCurrent += sizeof(struct REG_RFP);
647               if (prrfp->bCategory) {
648                 pCurrent += sizeof(DWORD);
649               }
650               for (j = 0; j < prrfp->dwMediaTypes; ++j) {
651                 struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent;
652                 pCurrent += sizeof(*prt);
653               }
654               for (j = 0; j < prrfp->dwMediums; ++j) {
655                 DWORD dwOffset = *(DWORD*) pCurrent;
656                 pCurrent += sizeof(dwOffset);
657               }
658             }
659
660             add_prop_ui4(pSubCont, dwInputs,  dwNInputs);
661             add_prop_ui4(pSubCont, dwOutputs, dwNOutputs);
662
663             SafeArrayUnaccessData(V_UNION(&v, parray));
664             VariantClear(&v);
665           }
666           IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
667         }
668         IEnumMoniker_Release(pEnum); pEnum = NULL;
669       }
670 class_enum_failed:      
671       SysFreeString(wszCatName);
672       SysFreeString(wszCatClsid);
673       IPropertyBag_Release(pPropBag); pPropBag = NULL;
674     }
675     IEnumMoniker_Release(pMCat); pMCat = NULL;
676   }
677
678 out_show_filters:
679   if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; }
680   if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; }
681   return hr;
682 }
683
684 HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
685   HRESULT hr = S_OK;
686   static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
687   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};
688   static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
689   static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
690   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};
691   static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
692   static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
693   static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
694   static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
695   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};
696   IDxDiagContainer* pSubCont = NULL;
697   
698   TRACE("(%p)\n", pRootCont);
699
700   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
701   if (FAILED(hr)) { return hr; }
702   hr = DXDiag_InitDXDiagSystemInfoContainer(pSubCont);
703   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
704
705   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
706   if (FAILED(hr)) { return hr; }
707   hr = DXDiag_InitDXDiagSystemDevicesContainer(pSubCont);
708   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemDevices, pSubCont);
709
710   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
711   if (FAILED(hr)) { return hr; }
712   hr = DXDiag_InitDXDiagLogicalDisksContainer(pSubCont);
713   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_LogicalDisks, pSubCont);
714
715   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
716   if (FAILED(hr)) { return hr; }
717   hr = DXDiag_InitDXDiagDirectXFilesContainer(pSubCont);
718   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectXFiles, pSubCont);
719
720   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
721   if (FAILED(hr)) { return hr; }
722   hr = DXDiag_InitDXDiagDisplayContainer(pSubCont);
723   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DisplayDevices, pSubCont);
724
725   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
726   if (FAILED(hr)) { return hr; }
727   hr = DXDiag_InitDXDiagDirectSoundContainer(pSubCont);
728   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectSound, pSubCont);
729
730   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
731   if (FAILED(hr)) { return hr; }
732   hr = DXDiag_InitDXDiagDirectMusicContainer(pSubCont);
733   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectMusic, pSubCont);
734
735   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
736   if (FAILED(hr)) { return hr; }
737   hr = DXDiag_InitDXDiagDirectInputContainer(pSubCont);
738   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectInput, pSubCont);
739
740   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
741   if (FAILED(hr)) { return hr; }
742   hr = DXDiag_InitDXDiagDirectPlayContainer(pSubCont);
743   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectPlay, pSubCont);
744
745   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
746   if (FAILED(hr)) { return hr; }
747   hr = DXDiag_InitDXDiagDirectShowFiltersContainer(pSubCont);
748   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectShowFilters, pSubCont);
749
750   return hr;
751 }