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