msxml/tests: Use VariantInit, not VariantClear, to initialize new variants.
[wine/multimedia.git] / dlls / dxdiagn / provider.c
blob7fc7aa5cdff9aebccc6a476b80952d569d5caab9
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004-2005 Raphael Junqueira
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.
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.
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
22 #include "config.h"
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"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
40 /* IDxDiagProvider IUnknown parts follow: */
41 static HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
43 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
45 if (IsEqualGUID(riid, &IID_IUnknown)
46 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
47 IUnknown_AddRef(iface);
48 *ppobj = This;
49 return S_OK;
52 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
53 return E_NOINTERFACE;
56 static ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
57 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
58 ULONG refCount = InterlockedIncrement(&This->ref);
60 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
62 DXDIAGN_LockModule();
64 return refCount;
67 static ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
68 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
69 ULONG refCount = InterlockedDecrement(&This->ref);
71 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
73 if (!refCount) {
74 HeapFree(GetProcessHeap(), 0, This);
77 DXDIAGN_UnlockModule();
79 return refCount;
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);
87 if (NULL == pParams) {
88 return E_POINTER;
90 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
91 return E_INVALIDARG;
94 This->init = TRUE;
95 memcpy(&This->params, pParams, pParams->dwSize);
96 return S_OK;
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);
104 if (NULL == ppInstance) {
105 return E_INVALIDARG;
107 if (FALSE == This->init) {
108 return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
110 if (NULL == This->pRootContainer) {
111 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
112 if (FAILED(hr)) {
113 return hr;
115 hr = DXDiag_InitRootDXDiagContainer(This->pRootContainer);
117 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
120 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
122 IDxDiagProviderImpl_QueryInterface,
123 IDxDiagProviderImpl_AddRef,
124 IDxDiagProviderImpl_Release,
125 IDxDiagProviderImpl_Initialize,
126 IDxDiagProviderImpl_GetRootContainer
129 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
130 IDxDiagProviderImpl* provider;
132 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
134 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
135 if (NULL == provider) {
136 *ppobj = NULL;
137 return E_OUTOFMEMORY;
139 provider->lpVtbl = &DxDiagProvider_Vtbl;
140 provider->ref = 0; /* will be inited with QueryInterface */
141 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
144 static inline HRESULT add_prop_str( IDxDiagContainer* cont, LPCWSTR prop, LPCWSTR str )
146 HRESULT hr;
147 VARIANT var;
149 V_VT( &var ) = VT_BSTR;
150 V_BSTR( &var ) = SysAllocString( str );
151 hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
152 VariantClear( &var );
154 return hr;
157 static inline HRESULT add_prop_ui4( IDxDiagContainer* cont, LPCWSTR prop, DWORD data )
159 HRESULT hr;
160 VARIANT var;
162 V_VT( &var ) = VT_UI4;
163 V_UI4( &var ) = data;
164 hr = IDxDiagContainerImpl_AddProp( cont, prop, &var );
165 VariantClear( &var );
167 return hr;
171 * @param szFilePath: usually GetSystemDirectoryW
172 * @param szFileName: name of the dll without path
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;
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;
202 FIXME("(%p,%s)\n", pSubCont, debugstr_w(szFileName));
204 lstrcpyW(szFile, szFilePath);
205 lstrcatW(szFile, szSlashSep);
206 lstrcatW(szFile, szFileName);
208 retval = GetFileVersionInfoSizeW(szFile, &hdl);
209 pVersionInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
210 boolret = GetFileVersionInfoW(szFile, 0, retval, pVersionInfo);
211 boolret = VerQueryValueW(pVersionInfo, szSlashSep, (LPVOID) &pFileInfo, &uiLength);
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);
223 if (boolret) {
224 snprintfW(szVersion_v, sizeof(szVersion_v)/sizeof(szVersion_v[0]),
225 szVersionFormat,
226 HIWORD(pFileInfo->dwFileVersionMS),
227 LOWORD(pFileInfo->dwFileVersionMS),
228 HIWORD(pFileInfo->dwFileVersionLS),
229 LOWORD(pFileInfo->dwFileVersionLS));
231 TRACE("Found version as (%s)\n", debugstr_w(szVersion_v));
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);
256 HeapFree(GetProcessHeap(), 0, pVersionInfo);
258 return hr;
261 static HRESULT DXDiag_InitDXDiagSystemInfoContainer(IDxDiagContainer* pSubCont) {
262 static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
263 static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
264 static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
265 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
266 static const WCHAR bDebug[] = {'b','D','e','b','u','g',0};
267 static const WCHAR szDirectXVersionEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','E','n','g','l','i','s','h',0};
268 static const WCHAR szDirectXVersionEnglish_v[] = {'4','.','0','9','.','0','0','0','0','.','0','9','0','4',0};
269 static const WCHAR szDirectXVersionLongEnglish[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','o','n','g','E','n','g','l','i','s','h',0};
270 static const WCHAR szDirectXVersionLongEnglish_v[] = {'=',' ','"','D','i','r','e','c','t','X',' ','9','.','0','c',' ','(','4','.','0','9','.','0','0','0','0','.','0','9','0','4',')',0};
271 static const WCHAR ullPhysicalMemory[] = {'u','l','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
272 /*static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};*/
273 /*szWindowsDir*/
274 /*szWindowsDir*/
275 static const WCHAR dwOSMajorVersion[] = {'d','w','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
276 static const WCHAR dwOSMinorVersion[] = {'d','w','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
277 static const WCHAR dwOSBuildNumber[] = {'d','w','O','S','B','u','i','l','d','N','u','m','b','e','r',0};
278 static const WCHAR dwOSPlatformID[] = {'d','w','O','S','P','l','a','t','f','o','r','m','I','D',0};
279 MEMORYSTATUSEX msex;
280 OSVERSIONINFOW info;
281 VARIANT v;
283 V_VT(&v) = VT_UI4; V_UI4(&v) = 9;
284 IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMajor, &v);
285 V_VT(&v) = VT_UI4; V_UI4(&v) = 0;
286 IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMinor, &v);
287 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(szDirectXVersionLetter_v);
288 IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionLetter, &v);
289 VariantClear(&v);
290 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(szDirectXVersionEnglish_v);
291 IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionEnglish, &v);
292 VariantClear(&v);
293 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(szDirectXVersionLongEnglish_v);
294 IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionLongEnglish, &v);
295 VariantClear(&v);
296 V_VT(&v) = VT_BOOL; V_BOOL(&v) = FALSE;
297 IDxDiagContainerImpl_AddProp(pSubCont, bDebug, &v);
299 msex.dwLength = sizeof(msex);
300 GlobalMemoryStatusEx( &msex );
301 V_VT(&v) = VT_UI8;
302 V_UI8(&v) = msex.ullTotalPhys;
303 IDxDiagContainerImpl_AddProp(pSubCont, ullPhysicalMemory, &v);
305 info.dwOSVersionInfoSize = sizeof(info);
306 GetVersionExW( &info );
307 V_VT(&v) = VT_UI4;
308 V_UI4(&v) = info.dwMajorVersion;
309 IDxDiagContainerImpl_AddProp(pSubCont, dwOSMajorVersion, &v);
310 V_VT(&v) = VT_UI4;
311 V_UI4(&v) = info.dwMinorVersion;
312 IDxDiagContainerImpl_AddProp(pSubCont, dwOSMinorVersion, &v);
313 V_VT(&v) = VT_UI4;
314 V_UI4(&v) = info.dwBuildNumber;
315 IDxDiagContainerImpl_AddProp(pSubCont, dwOSBuildNumber, &v);
316 V_VT(&v) = VT_UI4;
317 V_UI4(&v) = info.dwPlatformId;
318 IDxDiagContainerImpl_AddProp(pSubCont, dwOSPlatformID, &v);
320 return S_OK;
323 static HRESULT DXDiag_InitDXDiagSystemDevicesContainer(IDxDiagContainer* pSubCont) {
324 HRESULT hr = S_OK;
326 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
327 static const WCHAR szDeviceID[] = {'s','z','D','e','v','i','c','e','I','D',0};
329 static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
331 VARIANT v;
332 IDxDiagContainer* pDeviceSubCont = NULL;
333 IDxDiagContainer* pDriversCont = NULL;
335 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDeviceSubCont);
336 if (FAILED(hr)) { return hr; }
337 V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
338 hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDescription, &v);
339 VariantClear(&v);
340 V_VT(pvarProp) = VT_BSTR; V_BSTR(pvarProp) = SysAllocString(property->psz);
341 hr = IDxDiagContainerImpl_AddProp(pDeviceSubCont, szDeviceID, &v);
342 VariantClear(&v);
344 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "", pDeviceSubCont);
348 * Drivers Cont contains Files Desc Containers
351 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
352 if (FAILED(hr)) { return hr; }
353 hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
356 return hr;
359 static HRESULT DXDiag_InitDXDiagLogicalDisksContainer(IDxDiagContainer* pSubCont) {
360 HRESULT hr = S_OK;
362 static const WCHAR szDriveLetter[] = {'s','z','D','r','i','v','e','L','e','t','t','e','r',0};
363 static const WCHAR szFreeSpace[] = {'s','z','F','r','e','e','S','p','a','c','e',0};
364 static const WCHAR szMaxSpace[] = {'s','z','M','a','x','S','p','a','c','e',0};
365 static const WCHAR szFileSystem[] = {'s','z','F','i','l','e','S','y','s','t','e','m',0};
366 static const WCHAR szModel[] = {'s','z','M','o','d','e','l',0};
367 static const WCHAR szPNPDeviceID[] = {'s','z','P','N','P','D','e','v','i','c','e','I','D',0};
368 static const WCHAR dwHardDriveIndex[] = {'d','w','H','a','r','d','D','r','i','v','e','I','n','d','e','x',0};
370 static const WCHAR szDrivers[] = {'s','z','D','r','i','v','e','r','s',0};
372 VARIANT v;
373 IDxDiagContainer* pDiskSubCont = NULL;
374 IDxDiagContainer* pDriversCont = NULL;
376 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDiskSubCont);
377 if (FAILED(hr)) { return hr; }
378 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, "" , pDiskSubCont);
382 * Drivers Cont contains Files Desc Containers
385 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pDriversCont);
386 if (FAILED(hr)) { return hr; }
387 hr = IDxDiagContainerImpl_AddChildContainer(pDeviceSubCont, szDrivers, pDriversCont);
389 return hr;
391 static HRESULT DXDiag_InitDXDiagDirectXFilesContainer(IDxDiagContainer* pSubCont) {
392 HRESULT hr = S_OK;
393 /**/
394 static const WCHAR ddraw_dll[] = {'d','d','r','a','w','.','d','l','l',0};
395 static const WCHAR dplayx_dll[] = {'d','p','l','a','y','x','.','d','l','l',0};
396 static const WCHAR dpnet_dll[] = {'d','p','n','e','t','.','d','l','l',0};
397 static const WCHAR dinput_dll[] = {'d','i','n','p','u','t','.','d','l','l',0};
398 static const WCHAR dinput8_dll[] = {'d','i','n','p','u','t','8','.','d','l','l',0};
399 static const WCHAR dsound_dll[] = {'d','s','o','u','n','d','.','d','l','l',0};
400 static const WCHAR dswave_dll[] = {'d','s','w','a','v','e','.','d','l','l',0};
401 static const WCHAR d3d8_dll[] = {'d','3','d','8','.','d','l','l',0};
402 static const WCHAR d3d9_dll[] = {'d','3','d','9','.','d','l','l',0};
403 static const WCHAR dmband_dll[] = {'d','m','b','a','n','d','.','d','l','l',0};
404 static const WCHAR dmcompos_dll[] = {'d','m','c','o','m','p','o','s','.','d','l','l',0};
405 static const WCHAR dmime_dll[] = {'d','m','i','m','e','.','d','l','l',0};
406 static const WCHAR dmloader_dll[] = {'d','m','l','o','a','d','e','r','.','d','l','l',0};
407 static const WCHAR dmscript_dll[] = {'d','m','s','c','r','i','p','t','.','d','l','l',0};
408 static const WCHAR dmstyle_dll[] = {'d','m','s','t','y','l','e','.','d','l','l',0};
409 static const WCHAR dmsynth_dll[] = {'d','m','s','y','n','t','h','.','d','l','l',0};
410 static const WCHAR dmusic_dll[] = {'d','m','u','s','i','c','.','d','l','l',0};
411 static const WCHAR devenum_dll[] = {'d','e','v','e','n','u','m','.','d','l','l',0};
412 static const WCHAR quartz_dll[] = {'q','u','a','r','t','z','.','d','l','l',0};
413 WCHAR szFilePath[512];
415 hr = GetSystemDirectoryW(szFilePath, MAX_PATH);
416 if (FAILED(hr)) { return hr; }
417 szFilePath[MAX_PATH-1]=0;
419 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, ddraw_dll);
420 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dplayx_dll);
421 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dpnet_dll);
422 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput_dll);
423 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dinput8_dll);
424 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dsound_dll);
425 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dswave_dll);
426 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d8_dll);
427 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, d3d9_dll);
428 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmband_dll);
429 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmcompos_dll);
430 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmime_dll);
431 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmloader_dll);
432 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmscript_dll);
433 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmstyle_dll);
434 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmsynth_dll);
435 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, dmusic_dll);
436 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, devenum_dll);
437 hr = DXDiag_AddFileDescContainer(pSubCont, szFilePath, quartz_dll);
438 return hr;
441 static HRESULT DXDiag_InitDXDiagDisplayContainer(IDxDiagContainer* pSubCont)
443 static const WCHAR szDescription[] = {'s','z','D','e','s','c','r','i','p','t','i','o','n',0};
444 static const WCHAR szDeviceName[] = {'s','z','D','e','v','i','c','e','N','a','m','e',0};
445 static const WCHAR szKeyDeviceID[] = {'s','z','K','e','y','D','e','v','i','c','e','I','D',0};
446 static const WCHAR szKeyDeviceKey[] = {'s','z','K','e','y','D','e','v','i','c','e','K','e','y',0};
447 static const WCHAR szVendorId[] = {'s','z','V','e','n','d','o','r','I','d',0};
448 static const WCHAR szDeviceId[] = {'s','z','D','e','v','i','c','e','I','d',0};
449 static const WCHAR dwWidth[] = {'d','w','W','i','d','t','h',0};
450 static const WCHAR dwHeight[] = {'d','w','H','e','i','g','h','t',0};
451 static const WCHAR dwBpp[] = {'d','w','B','p','p',0};
452 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};
453 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};
455 static const WCHAR szAdapterID[] = {'0',0};
456 static const WCHAR szEmpty[] = {0};
458 HRESULT hr;
459 IDxDiagContainer *pDisplayAdapterSubCont = NULL;
461 IDirectDraw7 *pDirectDraw;
462 DDSCAPS2 dd_caps;
463 DISPLAY_DEVICEW disp_dev;
464 DDSURFACEDESC2 surface_descr;
465 DWORD tmp;
466 WCHAR buffer[256];
468 hr = DXDiag_CreateDXDiagContainer( &IID_IDxDiagContainer, (void**) &pDisplayAdapterSubCont );
469 if (FAILED( hr )) return hr;
470 hr = IDxDiagContainerImpl_AddChildContainer( pSubCont, szAdapterID, pDisplayAdapterSubCont );
471 if (FAILED( hr )) return hr;
473 if (EnumDisplayDevicesW( NULL, 0, &disp_dev, 0 ))
475 add_prop_str( pDisplayAdapterSubCont, szDeviceName, disp_dev.DeviceName );
476 add_prop_str( pDisplayAdapterSubCont, szDescription, disp_dev.DeviceString );
479 hr = DirectDrawCreateEx( NULL, (LPVOID *)&pDirectDraw, &IID_IDirectDraw7, NULL);
480 if (FAILED( hr )) return hr;
482 dd_caps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
483 dd_caps.dwCaps2 = dd_caps.dwCaps3 = dd_caps.dwCaps4 = 0;
484 hr = IDirectDraw7_GetAvailableVidMem( pDirectDraw, &dd_caps, &tmp, NULL );
485 if (SUCCEEDED(hr))
487 static const WCHAR mem_fmt[] = {'%','.','1','f',' ','M','B',0};
489 snprintfW( buffer, sizeof(buffer)/sizeof(buffer[0]), mem_fmt, ((float)tmp) / 1000000.0 );
490 add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryLocalized, buffer );
491 add_prop_str( pDisplayAdapterSubCont, szDisplayMemoryEnglish, buffer );
494 surface_descr.dwSize = sizeof(surface_descr);
495 hr = IDirectDraw7_GetDisplayMode( pDirectDraw, &surface_descr );
496 if (SUCCEEDED(hr))
498 if (surface_descr.dwFlags & DDSD_WIDTH)
499 add_prop_ui4( pDisplayAdapterSubCont, dwWidth, surface_descr.dwWidth );
500 if (surface_descr.dwFlags & DDSD_HEIGHT)
501 add_prop_ui4( pDisplayAdapterSubCont, dwHeight, surface_descr.dwHeight );
502 if (surface_descr.dwFlags & DDSD_PIXELFORMAT)
503 add_prop_ui4( pDisplayAdapterSubCont, dwBpp, surface_descr.u4.ddpfPixelFormat.u1.dwRGBBitCount );
506 add_prop_str( pDisplayAdapterSubCont, szVendorId, szEmpty );
507 add_prop_str( pDisplayAdapterSubCont, szDeviceId, szEmpty );
508 add_prop_str( pDisplayAdapterSubCont, szKeyDeviceKey, szEmpty );
509 add_prop_str( pDisplayAdapterSubCont, szKeyDeviceID, szEmpty );
511 IUnknown_Release( pDirectDraw );
512 return hr;
515 static HRESULT DXDiag_InitDXDiagDirectSoundContainer(IDxDiagContainer* pSubCont) {
516 HRESULT hr = S_OK;
517 static const WCHAR DxDiag_SoundDevices[] = {'D','x','D','i','a','g','_','S','o','u','n','d','D','e','v','i','c','e','s',0};
518 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};
519 IDxDiagContainer* pSubSubCont = NULL;
521 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
522 if (FAILED(hr)) { return hr; }
523 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundDevices, pSubSubCont);
525 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubSubCont);
526 if (FAILED(hr)) { return hr; }
527 hr = IDxDiagContainerImpl_AddChildContainer(pSubCont, DxDiag_SoundCaptureDevices, pSubSubCont);
529 return hr;
532 static HRESULT DXDiag_InitDXDiagDirectMusicContainer(IDxDiagContainer* pSubCont) {
533 HRESULT hr = S_OK;
534 return hr;
537 static HRESULT DXDiag_InitDXDiagDirectInputContainer(IDxDiagContainer* pSubCont) {
538 HRESULT hr = S_OK;
539 return hr;
542 static HRESULT DXDiag_InitDXDiagDirectPlayContainer(IDxDiagContainer* pSubCont) {
543 HRESULT hr = S_OK;
544 return hr;
547 struct REG_RF {
548 DWORD dwVersion;
549 DWORD dwMerit;
550 DWORD dwPins;
551 DWORD dwUnused;
553 struct REG_RFP {
554 BYTE signature[4]; /* e.g. "0pi3" */
555 DWORD dwFlags;
556 DWORD dwInstances;
557 DWORD dwMediaTypes;
558 DWORD dwMediums;
559 DWORD bCategory; /* is there a category clsid? */
560 /* optional: dwOffsetCategoryClsid */
562 struct REG_TYPE {
563 BYTE signature[4]; /* e.g. "0ty3" */
564 DWORD dwUnused;
565 DWORD dwOffsetMajor;
566 DWORD dwOffsetMinor;
569 static HRESULT DXDiag_InitDXDiagDirectShowFiltersContainer(IDxDiagContainer* pSubCont) {
570 HRESULT hr = S_OK;
571 static const WCHAR szName[] = {'s','z','N','a','m','e',0};
572 static const WCHAR szCatName[] = {'s','z','C','a','t','N','a','m','e',0};
573 static const WCHAR szClsidCat[] = {'s','z','C','l','s','i','d','C','a','t',0};
574 static const WCHAR szClsidFilter[] = {'s','z','C','l','s','i','d','F','i','l','t','e','r',0};
575 static const WCHAR dwInputs[] = {'d','w','I','n','p','u','t','s',0};
576 static const WCHAR dwOutputs[] = {'d','w','O','u','t','p','u','t','s',0};
577 static const WCHAR dwMerit[] = {'d','w','M','e','r','i','t',0};
579 static const WCHAR szFileName[] = {'s','z','F','i','l','e','N','a','m','e',0};
580 static const WCHAR szFileVersion[] = {'s','z','F','i','l','e','V','e','r','s','i','o','n',0};
582 VARIANT v;
584 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
585 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
586 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
587 /*static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};*/
589 ICreateDevEnum* pCreateDevEnum = NULL;
590 IEnumMoniker* pEmCat = NULL;
591 IMoniker* pMCat = NULL;
592 /** */
593 hr = CoCreateInstance(&CLSID_SystemDeviceEnum,
594 NULL,
595 CLSCTX_INPROC_SERVER,
596 &IID_ICreateDevEnum,
597 (void**) &pCreateDevEnum);
598 if (FAILED(hr)) return hr;
600 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEmCat, 0);
601 if (FAILED(hr)) goto out_show_filters;
603 VariantInit(&v);
605 while (S_OK == IEnumMoniker_Next(pEmCat, 1, &pMCat, NULL)) {
606 IPropertyBag* pPropBag = NULL;
607 CLSID clsidCat;
608 hr = IMoniker_BindToStorage(pMCat, NULL, NULL, &IID_IPropertyBag, (void**) &pPropBag);
609 if (SUCCEEDED(hr)) {
610 WCHAR* wszCatName = NULL;
611 WCHAR* wszCatClsid = NULL;
613 hr = IPropertyBag_Read(pPropBag, wszFriendlyName, &v, 0);
614 wszCatName = SysAllocString(V_BSTR(&v));
615 VariantClear(&v);
617 hr = IPropertyBag_Read(pPropBag, wszClsidName, &v, 0);
618 wszCatClsid = SysAllocString(V_BSTR(&v));
619 hr = CLSIDFromString(V_UNION(&v, bstrVal), &clsidCat);
620 VariantClear(&v);
623 hr = IPropertyBag_Read(pPropBag, wszMeritName, &v, 0);
624 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v);
625 VariantClear(&v);
628 if (SUCCEEDED(hr)) {
629 IEnumMoniker* pEnum = NULL;
630 IMoniker* pMoniker = NULL;
631 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
632 FIXME("\tClassEnumerator for clsid(%s) pEnum(%p)\n", debugstr_guid(&clsidCat), pEnum);
633 if (FAILED(hr) || pEnum == NULL) {
634 goto class_enum_failed;
636 while (NULL != pEnum && S_OK == IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL)) {
637 IPropertyBag* pPropFilterBag = NULL;
638 FIXME("\tIEnumMoniker_Next(%p, 1, %p)\n", pEnum, pMoniker);
639 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (void**) &pPropFilterBag);
640 if (SUCCEEDED(hr)) {
641 LPBYTE pData = NULL;
642 LPBYTE pCurrent = NULL;
643 struct REG_RF* prrf = NULL;
644 VARIANT v_data;
645 DWORD it;
646 DWORD dwNOutputs = 0;
647 DWORD dwNInputs = 0;
649 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(wszCatName);
650 hr = IDxDiagContainerImpl_AddProp(pSubCont, szCatName, &v);
651 VariantClear(&v);
653 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(wszCatClsid);
654 hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidCat, &v);
655 VariantClear(&v);
657 hr = IPropertyBag_Read(pPropFilterBag, wszFriendlyName, &v, 0);
658 hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v);
659 FIXME("\tName:%s\n", debugstr_w(V_BSTR(&v)));
660 VariantClear(&v);
662 hr = IPropertyBag_Read(pPropFilterBag, wszClsidName, &v, 0);
663 FIXME("\tClsid:%s\n", debugstr_w(V_BSTR(&v)));
664 hr = IDxDiagContainerImpl_AddProp(pSubCont, szClsidFilter, &v);
665 VariantClear(&v);
667 hr = IPropertyBag_Read(pPropFilterBag, wszFilterDataName, &v, NULL);
668 hr = SafeArrayAccessData(V_UNION(&v, parray), (LPVOID*) &pData);
669 prrf = (struct REG_RF*) pData;
670 pCurrent = pData;
672 VariantInit(&v_data);
673 V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = prrf->dwVersion;
674 hr = IDxDiagContainerImpl_AddProp(pSubCont, szName, &v_data);
675 VariantClear(&v_data);
676 V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = prrf->dwMerit;
677 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwMerit, &v_data);
678 VariantClear(&v_data);
680 pCurrent += sizeof(struct REG_RF);
681 for (it = 0; it < prrf->dwPins; ++it) {
682 struct REG_RFP* prrfp = (struct REG_RFP*) pCurrent;
683 UINT j;
685 if (prrfp->dwFlags & REG_PINFLAG_B_OUTPUT) ++dwNOutputs;
686 else ++dwNInputs;
688 pCurrent += sizeof(struct REG_RFP);
689 if (prrfp->bCategory) {
690 pCurrent += sizeof(DWORD);
692 for (j = 0; j < prrfp->dwMediaTypes; ++j) {
693 struct REG_TYPE* prt = (struct REG_TYPE *)pCurrent;
694 pCurrent += sizeof(*prt);
696 for (j = 0; j < prrfp->dwMediums; ++j) {
697 DWORD dwOffset = *(DWORD*) pCurrent;
698 pCurrent += sizeof(dwOffset);
702 V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = dwNInputs;
703 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwInputs, &v_data);
704 VariantClear(&v_data);
705 V_VT(&v_data) = VT_UI4; V_UI4(&v_data) = dwNOutputs;
706 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwOutputs, &v_data);
707 VariantClear(&v_data);
709 SafeArrayUnaccessData(V_UNION(&v, parray));
710 VariantClear(&v);
712 IPropertyBag_Release(pPropFilterBag); pPropFilterBag = NULL;
714 IEnumMoniker_Release(pEnum); pEnum = NULL;
716 class_enum_failed:
717 SysFreeString(wszCatName);
718 SysFreeString(wszCatClsid);
719 IPropertyBag_Release(pPropBag); pPropBag = NULL;
721 IEnumMoniker_Release(pMCat); pMCat = NULL;
724 out_show_filters:
725 if (NULL != pEmCat) { IEnumMoniker_Release(pEmCat); pEmCat = NULL; }
726 if (NULL != pCreateDevEnum) { ICreateDevEnum_Release(pCreateDevEnum); pCreateDevEnum = NULL; }
727 return hr;
730 HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
731 HRESULT hr = S_OK;
732 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
733 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};
734 static const WCHAR DxDiag_LogicalDisks[] = {'D','x','D','i','a','g','_','L','o','g','i','c','a','l','D','i','s','k','s',0};
735 static const WCHAR DxDiag_DirectXFiles[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','X','F','i','l','e','s',0};
736 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};
737 static const WCHAR DxDiag_DirectSound[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','S','o','u','n','d',0};
738 static const WCHAR DxDiag_DirectMusic[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','M','u','s','i','c',0};
739 static const WCHAR DxDiag_DirectInput[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','I','n','p','u','t',0};
740 static const WCHAR DxDiag_DirectPlay[] = {'D','x','D','i','a','g','_','D','i','r','e','c','t','P','l','a','y',0};
741 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};
742 IDxDiagContainer* pSubCont = NULL;
744 TRACE("(%p)\n", pRootCont);
746 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
747 if (FAILED(hr)) { return hr; }
748 hr = DXDiag_InitDXDiagSystemInfoContainer(pSubCont);
749 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
751 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
752 if (FAILED(hr)) { return hr; }
753 hr = DXDiag_InitDXDiagSystemDevicesContainer(pSubCont);
754 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemDevices, pSubCont);
756 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
757 if (FAILED(hr)) { return hr; }
758 hr = DXDiag_InitDXDiagLogicalDisksContainer(pSubCont);
759 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_LogicalDisks, pSubCont);
761 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
762 if (FAILED(hr)) { return hr; }
763 hr = DXDiag_InitDXDiagDirectXFilesContainer(pSubCont);
764 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectXFiles, pSubCont);
766 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
767 if (FAILED(hr)) { return hr; }
768 hr = DXDiag_InitDXDiagDisplayContainer(pSubCont);
769 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DisplayDevices, pSubCont);
771 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
772 if (FAILED(hr)) { return hr; }
773 hr = DXDiag_InitDXDiagDirectSoundContainer(pSubCont);
774 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectSound, pSubCont);
776 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
777 if (FAILED(hr)) { return hr; }
778 hr = DXDiag_InitDXDiagDirectMusicContainer(pSubCont);
779 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectMusic, pSubCont);
781 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
782 if (FAILED(hr)) { return hr; }
783 hr = DXDiag_InitDXDiagDirectInputContainer(pSubCont);
784 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectInput, pSubCont);
786 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
787 if (FAILED(hr)) { return hr; }
788 hr = DXDiag_InitDXDiagDirectPlayContainer(pSubCont);
789 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectPlay, pSubCont);
791 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
792 if (FAILED(hr)) { return hr; }
793 hr = DXDiag_InitDXDiagDirectShowFiltersContainer(pSubCont);
794 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_DirectShowFilters, pSubCont);
796 return hr;