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