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