gdiplus: Implement GdipRegionGetHRgn for paths.
[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 static inline HRESULT add_prop_ull_as_str( IDxDiagContainer* cont, LPCWSTR prop, ULONGLONG data )
176 {
177     HRESULT hr;
178     VARIANT var;
179
180     V_VT( &var ) = VT_UI8;
181     V_UI8( &var ) = data;
182     VariantChangeType( &var, &var, 0, VT_BSTR );
183     hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
184     VariantClear( &var );
185
186     return hr;
187 }
188
189 /**
190  * @param szFilePath: usually GetSystemDirectoryW
191  * @param szFileName: name of the dll without path
192  */
193 static HRESULT DXDiag_AddFileDescContainer(IDxDiagContainer* pSubCont, const WCHAR* szFilePath, const WCHAR* szFileName) {
194   HRESULT hr = S_OK;
195   /**/
196   static const WCHAR szSlashSep[] = {'\\',0};
197   static const WCHAR szPath[] = {'s','z','P','a','t','h',0};
198   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
199   static const WCHAR szVersion[] = {'s','z','V','e','r','s','i','o','n',0};
200   static const WCHAR szAttributes[] = {'s','z','A','t','t','r','i','b','u','t','e','s',0};
201   static const WCHAR szLanguageEnglish[] = {'s','z','L','a','n','g','u','a','g','e','E','n','g','l','i','s','h',0};
202   static const WCHAR dwFileTimeHigh[] = {'d','w','F','i','l','e','T','i','m','e','H','i','g','h',0};
203   static const WCHAR dwFileTimeLow[] = {'d','w','F','i','l','e','T','i','m','e','L','o','w',0};
204   static const WCHAR bBeta[] = {'b','B','e','t','a',0};
205   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
206   static const WCHAR bExists[] = {'b','E','x','i','s','t','s',0};
207   /** values */
208   static const WCHAR szFinal_Retail_v[] = {'F','i','n','a','l',' ','R','e','t','a','i','l',0};
209   static const WCHAR szEnglish_v[] = {'E','n','g','l','i','s','h',0};
210   static const WCHAR szVersionFormat[] = {'%','u','.','%','0','2','u','.','%','0','4','u','.','%','0','4','u',0};
211
212   WCHAR szFile[512];
213   WCHAR szVersion_v[1024];
214   DWORD retval, hdl;
215   LPVOID pVersionInfo;
216   BOOL boolret;
217   UINT uiLength;
218   VS_FIXEDFILEINFO* pFileInfo;
219
220   TRACE("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
221
222   lstrcpyW(szFile, szFilePath);
223   lstrcatW(szFile, szSlashSep);
224   lstrcatW(szFile, szFileName);
225
226   retval = GetFileVersionInfoSizeW(szFile, &hdl);
227   pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
228   boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
229   boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
230
231   add_prop_str(pSubCont, szPath, szFile);
232   add_prop_str(pSubCont, szName, szFileName);
233   add_prop_bool(pSubCont, bExists, boolret);
234
235   if (boolret) {
236     snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
237               szVersionFormat,
238               HIWORD(pFileInfo->dwFileVersionMS), 
239               LOWORD(pFileInfo->dwFileVersionMS),
240               HIWORD(pFileInfo->dwFileVersionLS),
241               LOWORD(pFileInfo->dwFileVersionLS));
242
243     TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
244
245     add_prop_str(pSubCont, szVersion,         szVersion_v);
246     add_prop_str(pSubCont, szAttributes,      szFinal_Retail_v);
247     add_prop_str(pSubCont, szLanguageEnglish, szEnglish_v);
248     add_prop_ui4(pSubCont, dwFileTimeHigh,    pFileInfo->dwFileDateMS);
249     add_prop_ui4(pSubCont, dwFileTimeLow,     pFileInfo->dwFileDateLS);
250     add_prop_bool(pSubCont, bBeta,  0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_PRERELEASE));
251     add_prop_bool(pSubCont, bDebug, 0 != ((pFileInfo->dwFileFlags & pFileInfo->dwFileFlagsMask) & VS_FF_DEBUG));
252   }
253
254   HeapFree(GetProcessHeap(), 0, pVersionInfo);
255
256   return hr;
257 }
258
259 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
260   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};
261   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};
262   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};
263   static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
264   static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
265   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};
266   static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
267   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};
268   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};
269   static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
270   static const WCHAR ullUsedPageFile[]   = {'u','l','l','U','s','e','d','P','a','g','e','F','i','l','e',0};
271   static const WCHAR ullAvailPageFile[]  = {'u','l','l','A','v','a','i','l','P','a','g','e','F','i','l','e',0};
272   /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
273   static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
274   static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
275   static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
276   static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
277   static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
278   static const WCHAR szCSDVersion[] = {'s','z','C','S','D','V','e','r','s','i','o','n',0};
279   MEMORYSTATUSEX msex;
280   OSVERSIONINFOW info;
281   WCHAR buffer[MAX_PATH];
282
283   add_prop_ui4(pSubCont, dwDirectXVersionMajor, 9);
284   add_prop_ui4(pSubCont, dwDirectXVersionMinor, 0);
285   add_prop_str(pSubCont, szDirectXVersionLetter, szDirectXVersionLetter_v);
286   add_prop_str(pSubCont, szDirectXVersionEnglish, szDirectXVersionEnglish_v);
287   add_prop_str(pSubCont, szDirectXVersionLongEnglish, szDirectXVersionLongEnglish_v);
288   add_prop_bool(pSubCont, bDebug, FALSE);
289
290   msex.dwLength = sizeof(msex);
291   GlobalMemoryStatusEx( &msex );
292   add_prop_ull_as_str(pSubCont, ullPhysicalMemory, msex.ullTotalPhys);
293   add_prop_ull_as_str(pSubCont, ullUsedPageFile, msex.ullTotalPageFile - msex.ullAvailPageFile);
294   add_prop_ull_as_str(pSubCont, ullAvailPageFile, msex.ullAvailPageFile);
295
296   info.dwOSVersionInfoSize = sizeof(info);
297   GetVersionExW( &info );
298   add_prop_ui4(pSubCont, dwOSMajorVersion, info.dwMajorVersion);
299   add_prop_ui4(pSubCont, dwOSMinorVersion, info.dwMinorVersion);
300   add_prop_ui4(pSubCont, dwOSBuildNumber,  info.dwBuildNumber);
301   add_prop_ui4(pSubCont, dwOSPlatformID,   info.dwPlatformId);
302   add_prop_str(pSubCont, szCSDVersion,     info.szCSDVersion);
303
304   GetWindowsDirectoryW(buffer, MAX_PATH);
305   add_prop_str(pSubCont, szWindowsDir, buffer);
306
307   return S_OK;
308 }
309
310 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
311   HRESULT hr = S_OK;
312   /*
313   static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
314   static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
315
316   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
317
318   VARIANT v;
319   IDxDiagContainer* pDeviceSubCont = NULL;
320   IDxDiagContainer* pDriversCont = NULL;
321
322   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDeviceSubCont);
323   if (FAILED(hr)) { return hr; }
324   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
325   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
326   VariantClear(&v);
327   V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
328   hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
329   VariantClear(&v);
330
331   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
332   */
333
334   /*
335    * Drivers Cont contains Files Desc Containers
336    */
337   /*
338   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
339   if (FAILED(hr)) { return hr; }
340   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
341
342   */
343   return hr;
344 }
345
346 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
347   HRESULT hr = S_OK;
348   /*
349   static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
350   static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
351   static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
352   static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
353   static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
354   static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
355   static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
356
357   static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
358  
359   VARIANT v;
360   IDxDiagContainer* pDiskSubCont = NULL;
361   IDxDiagContainer* pDriversCont = NULL;
362
363   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDiskSubCont);
364   if (FAILED(hr)) { return hr; }
365   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
366   */
367   
368   /*
369    * Drivers Cont contains Files Desc Containers
370    */
371   /*
372   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
373   if (FAILED(hr)) { return hr; }
374   hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
375   */
376   return hr;
377 }
378 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont) {
379   HRESULT hr = S_OK;
380   /**/
381   static const WCHAR ddraw_dll[] = {'d','d','r','a','w','.','d','l','l',0};
382   static const WCHAR dplayx_dll[] = {'d','p','l','a','y','x','.','d','l','l',0};
383   static const WCHAR dpnet_dll[] = {'d','p','n','e','t','.','d','l','l',0};
384   static const WCHAR dinput_dll[] = {'d','i','n','p','u','t','.','d','l','l',0};
385   static const WCHAR dinput8_dll[] = {'d','i','n','p','u','t','8','.','d','l','l',0};
386   static const WCHAR dsound_dll[] = {'d','s','o','u','n','d','.','d','l','l',0};
387   static const WCHAR dswave_dll[] = {'d','s','w','a','v','e','.','d','l','l',0};
388   static const WCHAR d3d8_dll[] = {'d','3','d','8','.','d','l','l',0};
389   static const WCHAR d3d9_dll[] = {'d','3','d','9','.','d','l','l',0};
390   static const WCHAR dmband_dll[] = {'d','m','b','a','n','d','.','d','l','l',0};
391   static const WCHAR dmcompos_dll[] = {'d','m','c','o','m','p','o','s','.','d','l','l',0};
392   static const WCHAR dmime_dll[] =  {'d','m','i','m','e','.','d','l','l',0};
393   static const WCHAR dmloader_dll[] = {'d','m','l','o','a','d','e','r','.','d','l','l',0};
394   static const WCHAR dmscript_dll[] = {'d','m','s','c','r','i','p','t','.','d','l','l',0};
395   static const WCHAR dmstyle_dll[] = {'d','m','s','t','y','l','e','.','d','l','l',0};
396   static const WCHAR dmsynth_dll[] = {'d','m','s','y','n','t','h','.','d','l','l',0};
397   static const WCHAR dmusic_dll[] = {'d','m','u','s','i','c','.','d','l','l',0};
398   static const WCHAR devenum_dll[] = {'d','e','v','e','n','u','m','.','d','l','l',0};
399   static const WCHAR quartz_dll[] = {'q','u','a','r','t','z','.','d','l','l',0};
400   WCHAR szFilePath[512];
401
402   hr = GetSystemDirectoryW(szFilePath, MAX_PATH);
403   if (FAILED(hr)) { return hr; }  
404   szFilePath[MAX_PATH-1]=0;     
405
406   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, ddraw_dll);
407   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dplayx_dll);
408   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dpnet_dll);
409   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput_dll);
410   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput8_dll);
411   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dsound_dll);
412   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dswave_dll);
413   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d8_dll);
414   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d9_dll);
415   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmband_dll);
416   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmcompos_dll);
417   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmime_dll);
418   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmloader_dll);
419   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmscript_dll);
420   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmstyle_dll);
421   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmsynth_dll);
422   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmusic_dll);
423   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, devenum_dll);
424   hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, quartz_dll);
425   return hr;
426 }
427
428 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
429 {
430     static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
431     static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
432     static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
433     static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
434     static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
435     static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
436     static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
437     static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
438     static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
439     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};
440     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};
441
442     static const WCHAR szAdapterID[] = {'0',0};
443     static const WCHAR szEmpty[] = {0};
444
445     HRESULT                 hr;
446     IDxDiagContainer       *pDisplayAdapterSubCont = NULL;
447
448     IDirectDraw7           *pDirectDraw;
449     DDSCAPS2                dd_caps;
450     DISPLAY_DEVICEW         disp_dev;
451     DDSURFACEDESC2          surface_descr;
452     DWORD                   tmp;
453     WCHAR                   buffer[256];
454
455     hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
456     if (FAILED( hr )) return hr;
457     hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
458     if (FAILED( hr )) return hr;
459
460     if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
461     {
462         add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
463         add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
464     }
465
466     hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
467     if (FAILED( hr )) return hr;
468
469     dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
470     dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
471     hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
472     if (SUCCEEDED(hr))
473     {
474         static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
475
476         snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
477         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
478         add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
479     }
480
481     surface_descr.dwSize = sizeof(surface_descr);
482     hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
483     if (SUCCEEDED(hr))
484     {
485         if (surface_descr.dwFlags & DDSD_WIDTH)
486             add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
487         if (surface_descr.dwFlags & DDSD_HEIGHT)
488             add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
489         if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
490             add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
491     }
492
493     add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
494     add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
495     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
496     add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
497
498     IUnknown_Release( pDirectDraw );
499     return hr;
500 }
501
502 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
503   HRESULT hr = S_OK;
504   static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
505   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};
506   IDxDiagContainer* pSubSubCont = NULL;
507
508   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
509   if (FAILED(hr)) { return hr; }
510   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
511
512   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
513   if (FAILED(hr)) { return hr; }
514   hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
515
516   return hr;
517 }
518
519 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
520   HRESULT hr = S_OK;
521   return hr;
522 }
523
524 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
525   HRESULT hr = S_OK;
526   return hr;
527 }
528
529 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
530   HRESULT hr = S_OK;
531   return hr;
532 }
533
534 struct REG_RF {
535   DWORD dwVersion;
536   DWORD dwMerit;
537   DWORD dwPins;
538   DWORD dwUnused;
539 };
540 struct REG_RFP {
541   BYTE signature[4]; /* e.g. "0pi3" */
542   DWORD dwFlags;
543   DWORD dwInstances;
544   DWORD dwMediaTypes;
545   DWORD dwMediums;
546   DWORD bCategory; /* is there a category clsid? */
547   /* optional: dwOffsetCategoryClsid */
548 };
549 struct REG_TYPE {
550   BYTE signature[4]; /* e.g. "0ty3" */
551   DWORD dwUnused;
552   DWORD dwOffsetMajor;
553   DWORD dwOffsetMinor;
554 };
555
556 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
557   HRESULT hr = S_OK;
558   static const WCHAR szName[] = {'s','z','N','a','m','e',0};
559   static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
560   static const WCHAR szClsidCat[] = {'s','z','C','l','s','i','d','C','a','t',0};
561   static const WCHAR szClsidFilter[] = {'s','z','C','l','s','i','d','F','i','l','t','e','r',0};
562   static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
563   static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
564   static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0};
565   /*
566   static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
567   static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
568   */
569   VARIANT v;
570
571   static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
572   static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};  
573   static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
574   /*static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};*/
575
576   ICreateDevEnum* pCreateDevEnum = NULL;
577   IEnumMoniker* pEmCat = NULL;
578   IMoniker* pMCat = NULL;
579   /** */
580   hr = CoCreateInstance(&CLSID_SystemDeviceEnum, 
581                         NULL, 
582                         CLSCTX_INPROC_SERVER,
583                         &IID_ICreateDevEnum, 
584                         (void**) &pCreateDevEnum);
585   if (FAILED(hr)) return hr; 
586   
587   hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
588   if (FAILED(hr)) goto out_show_filters; 
589
590   VariantInit(&v);
591
592   while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
593     IPropertyBag* pPropBag = NULL;
594     CLSID clsidCat; 
595     hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
596     if (SUCCEEDED(hr)) {
597       WCHAR* wszCatName = NULL;
598       WCHAR* wszCatClsid = NULL;
599
600       hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
601       wszCatName = SysAllocString(V_BSTR(&v));
602       VariantClear(&v);
603
604       hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
605       wszCatClsid = SysAllocString(V_BSTR(&v));
606       hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
607       VariantClear(&v);
608
609       /*
610       hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
611       hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
612       VariantClear(&v);
613       */
614
615       if (SUCCEEDED(hr)) {
616         IEnumMoniker* pEnum = NULL;
617         IMoniker* pMoniker = NULL;
618         hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);        
619         TRACE("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
620         if (FAILED(hr) || pEnum == NULL) {
621           goto class_enum_failed;
622         }
623         while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {          
624           IPropertyBag* pPropFilterBag = NULL;
625           TRACE("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
626           hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
627           if (SUCCEEDED(hr)) {
628             LPBYTE pData = NULL;
629             LPBYTE pCurrent = NULL;
630             struct REG_RF* prrf = NULL;
631             DWORD it;
632             DWORD dwNOutputs = 0;
633             DWORD dwNInputs = 0;
634
635             add_prop_str(pSubCont, szCatName, wszCatName);
636             add_prop_str(pSubCont, szClsidCat, wszCatClsid);
637
638             hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
639             hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v);
640             TRACE("\tName:%s\n", debugstr_w(V_BSTR(&v)));
641             VariantClear(&v);
642
643             hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
644             TRACE("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
645             hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidFilter, &v);
646             VariantClear(&v);
647
648             hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
649             hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData);        
650             prrf = (struct REG_RF*) pData;
651             pCurrent = pData;
652
653             add_prop_ui4(pSubCont, szName, prrf->dwVersion);
654             add_prop_ui4(pSubCont, dwMerit, prrf->dwMerit);
655
656             pCurrent += sizeof(struct REG_RF);
657             for (it = 0; it < prrf->dwPins; ++it) {
658               struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent;
659               UINT j;
660
661               if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs;
662               else ++dwNInputs;
663
664               pCurrent += sizeof(struct REG_RFP);
665               if (prrfp->bCategory) {
666                 pCurrent += sizeof(DWORD);
667               }
668               for (j = 0; j < prrfp->dwMediaTypes; ++j) {
669                 struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent;
670                 pCurrent += sizeof(*prt);
671               }
672               for (j = 0; j < prrfp->dwMediums; ++j) {
673                 DWORD dwOffset = *(DWORD*) pCurrent;
674                 pCurrent += sizeof(dwOffset);
675               }
676             }
677
678             add_prop_ui4(pSubCont, dwInputs,  dwNInputs);
679             add_prop_ui4(pSubCont, dwOutputs, dwNOutputs);
680
681             SafeArrayUnaccessData(V_UNION(&v, parray));
682             VariantClear(&v);
683           }
684           IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
685         }
686         IEnumMoniker_Release(pEnum); pEnum = NULL;
687       }
688 class_enum_failed:      
689       SysFreeString(wszCatName);
690       SysFreeString(wszCatClsid);
691       IPropertyBag_Release(pPropBag); pPropBag = NULL;
692     }
693     IEnumMoniker_Release(pMCat); pMCat = NULL;
694   }
695
696 out_show_filters:
697   if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; }
698   if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; }
699   return hr;
700 }
701
702 HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
703   HRESULT hr = S_OK;
704   static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
705   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};
706   static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
707   static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
708   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};
709   static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
710   static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
711   static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
712   static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
713   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};
714   IDxDiagContainer* pSubCont = NULL;
715   
716   TRACE("(%p)\n", pRootCont);
717
718   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
719   if (FAILED(hr)) { return hr; }
720   hr = DXDiag_InitDXDiagSystemInfoContainer(pSubCont);
721   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
722
723   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
724   if (FAILED(hr)) { return hr; }
725   hr = DXDiag_InitDXDiagSystemDevicesContainer(pSubCont);
726   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemDevices, pSubCont);
727
728   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
729   if (FAILED(hr)) { return hr; }
730   hr = DXDiag_InitDXDiagLogicalDisksContainer(pSubCont);
731   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_LogicalDisks, pSubCont);
732
733   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
734   if (FAILED(hr)) { return hr; }
735   hr = DXDiag_InitDXDiagDirectXFilesContainer(pSubCont);
736   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectXFiles, pSubCont);
737
738   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
739   if (FAILED(hr)) { return hr; }
740   hr = DXDiag_InitDXDiagDisplayContainer(pSubCont);
741   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DisplayDevices, pSubCont);
742
743   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
744   if (FAILED(hr)) { return hr; }
745   hr = DXDiag_InitDXDiagDirectSoundContainer(pSubCont);
746   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectSound, pSubCont);
747
748   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
749   if (FAILED(hr)) { return hr; }
750   hr = DXDiag_InitDXDiagDirectMusicContainer(pSubCont);
751   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectMusic, pSubCont);
752
753   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
754   if (FAILED(hr)) { return hr; }
755   hr = DXDiag_InitDXDiagDirectInputContainer(pSubCont);
756   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectInput, pSubCont);
757
758   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
759   if (FAILED(hr)) { return hr; }
760   hr = DXDiag_InitDXDiagDirectPlayContainer(pSubCont);
761   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectPlay, pSubCont);
762
763   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
764   if (FAILED(hr)) { return hr; }
765   hr = DXDiag_InitDXDiagDirectShowFiltersContainer(pSubCont);
766   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectShowFilters, pSubCont);
767
768   return hr;
769 }