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