opengl32: Add a mechanism for managing different types of OpenGL handles.
[wine/multimedia.git] / programs / dxdiag / information.c
blob5cc862be63b728272edeb030526b525a19f82605
1 /*
2 * DxDiag information collection
4 * Copyright 2011 Andrew Nguyen
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
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <dxdiag.h>
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 #include "dxdiag_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
32 static const WCHAR szTimeEnglish[] = {'s','z','T','i','m','e','E','n','g','l','i','s','h',0};
33 static const WCHAR szTimeLocalized[] = {'s','z','T','i','m','e','L','o','c','a','l','i','z','e','d',0};
34 static const WCHAR szMachineNameEnglish[] = {'s','z','M','a','c','h','i','n','e','N','a','m','e','E','n','g','l','i','s','h',0};
35 static const WCHAR szOSExLongEnglish[] = {'s','z','O','S','E','x','L','o','n','g','E','n','g','l','i','s','h',0};
36 static const WCHAR szOSExLocalized[] = {'s','z','O','S','E','x','L','o','c','a','l','i','z','e','d',0};
37 static const WCHAR szLanguagesEnglish[] = {'s','z','L','a','n','g','u','a','g','e','s','E','n','g','l','i','s','h',0};
38 static const WCHAR szLanguagesLocalized[] = {'s','z','L','a','n','g','u','a','g','e','s','L','o','c','a','l','i','z','e','d',0};
39 static const WCHAR szSystemManufacturerEnglish[] = {'s','z','S','y','s','t','e','m','M','a','n','u','f','a','c','t','u','r','e','r','E','n','g','l','i','s','h',0};
40 static const WCHAR szSystemModelEnglish[] = {'s','z','S','y','s','t','e','m','M','o','d','e','l','E','n','g','l','i','s','h',0};
41 static const WCHAR szBIOSEnglish[] = {'s','z','B','I','O','S','E','n','g','l','i','s','h',0};
42 static const WCHAR szProcessorEnglish[] = {'s','z','P','r','o','c','e','s','s','o','r','E','n','g','l','i','s','h',0};
43 static const WCHAR szPhysicalMemoryEnglish[] = {'s','z','P','h','y','s','i','c','a','l','M','e','m','o','r','y','E','n','g','l','i','s','h',0};
44 static const WCHAR szPageFileEnglish[] = {'s','z','P','a','g','e','F','i','l','e','E','n','g','l','i','s','h',0};
45 static const WCHAR szPageFileLocalized[] = {'s','z','P','a','g','e','F','i','l','e','L','o','c','a','l','i','z','e','d',0};
46 static const WCHAR szWindowsDir[] = {'s','z','W','i','n','d','o','w','s','D','i','r',0};
47 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};
48 static const WCHAR szSetupParamEnglish[] = {'s','z','S','e','t','u','p','P','a','r','a','m','E','n','g','l','i','s','h',0};
49 static const WCHAR szDxDiagVersion[] = {'s','z','D','x','D','i','a','g','V','e','r','s','i','o','n',0};
51 struct property_list
53 const WCHAR *property_name;
54 WCHAR **output;
57 static BOOL property_to_string(IDxDiagContainer *container, const WCHAR *property, WCHAR **output)
59 VARIANT var;
60 HRESULT hr;
61 BOOL ret = FALSE;
63 VariantInit(&var);
65 hr = IDxDiagContainer_GetProp(container, property, &var);
66 if (SUCCEEDED(hr))
68 if (V_VT(&var) == VT_BSTR)
70 WCHAR *bstr = V_BSTR(&var);
72 *output = HeapAlloc(GetProcessHeap(), 0, (strlenW(bstr) + 1) * sizeof(WCHAR));
73 if (*output)
75 strcpyW(*output, bstr);
76 ret = TRUE;
81 VariantClear(&var);
82 return ret;
85 static void free_system_information(struct dxdiag_information *dxdiag_info)
87 struct system_information *system_info = &dxdiag_info->system_info;
89 HeapFree(GetProcessHeap(), 0, system_info->szTimeEnglish);
90 HeapFree(GetProcessHeap(), 0, system_info->szTimeLocalized);
91 HeapFree(GetProcessHeap(), 0, system_info->szMachineNameEnglish);
92 HeapFree(GetProcessHeap(), 0, system_info->szOSExLongEnglish);
93 HeapFree(GetProcessHeap(), 0, system_info->szOSExLocalized);
94 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesEnglish);
95 HeapFree(GetProcessHeap(), 0, system_info->szLanguagesLocalized);
96 HeapFree(GetProcessHeap(), 0, system_info->szSystemManufacturerEnglish);
97 HeapFree(GetProcessHeap(), 0, system_info->szSystemModelEnglish);
98 HeapFree(GetProcessHeap(), 0, system_info->szBIOSEnglish);
99 HeapFree(GetProcessHeap(), 0, system_info->szProcessorEnglish);
100 HeapFree(GetProcessHeap(), 0, system_info->szPhysicalMemoryEnglish);
101 HeapFree(GetProcessHeap(), 0, system_info->szPageFileEnglish);
102 HeapFree(GetProcessHeap(), 0, system_info->szPageFileLocalized);
103 HeapFree(GetProcessHeap(), 0, system_info->szWindowsDir);
104 HeapFree(GetProcessHeap(), 0, system_info->szDirectXVersionLongEnglish);
105 HeapFree(GetProcessHeap(), 0, system_info->szSetupParamEnglish);
106 HeapFree(GetProcessHeap(), 0, system_info->szDxDiagVersion);
109 static inline void fill_system_property_list(struct dxdiag_information *dxdiag_info, struct property_list *list)
111 struct system_information *system_info = &dxdiag_info->system_info;
113 list[0].property_name = szTimeEnglish;
114 list[0].output = &system_info->szTimeEnglish;
115 list[1].property_name = szTimeLocalized;
116 list[1].output = &system_info->szTimeLocalized;
117 list[2].property_name = szMachineNameEnglish;
118 list[2].output = &system_info->szMachineNameEnglish;
119 list[3].property_name = szOSExLongEnglish;
120 list[3].output = &system_info->szOSExLongEnglish;
121 list[4].property_name = szOSExLocalized;
122 list[4].output = &system_info->szOSExLocalized;
123 list[5].property_name = szLanguagesEnglish;
124 list[5].output = &system_info->szLanguagesEnglish;
125 list[6].property_name = szLanguagesLocalized;
126 list[6].output = &system_info->szLanguagesLocalized;
127 list[7].property_name = szSystemManufacturerEnglish;
128 list[7].output = &system_info->szSystemManufacturerEnglish;
129 list[8].property_name = szSystemModelEnglish;
130 list[8].output = &system_info->szSystemModelEnglish;
131 list[9].property_name = szBIOSEnglish;
132 list[9].output = &system_info->szBIOSEnglish;
133 list[10].property_name = szProcessorEnglish;
134 list[10].output = &system_info->szProcessorEnglish;
135 list[11].property_name = szPhysicalMemoryEnglish;
136 list[11].output = &system_info->szPhysicalMemoryEnglish;
137 list[12].property_name = szPageFileEnglish;
138 list[12].output = &system_info->szPageFileEnglish;
139 list[13].property_name = szPageFileLocalized;
140 list[13].output = &system_info->szPageFileLocalized;
141 list[14].property_name = szWindowsDir;
142 list[14].output = &system_info->szWindowsDir;
143 list[15].property_name = szDirectXVersionLongEnglish;
144 list[15].output = &system_info->szDirectXVersionLongEnglish;
145 list[16].property_name = szSetupParamEnglish;
146 list[16].output = &system_info->szSetupParamEnglish;
147 list[17].property_name = szDxDiagVersion;
148 list[17].output = &system_info->szDxDiagVersion;
151 static BOOL fill_system_information(IDxDiagContainer *container, struct dxdiag_information *dxdiag_info)
153 struct system_information *system_info = &dxdiag_info->system_info;
154 size_t i;
155 struct property_list property_list[18];
157 fill_system_property_list(dxdiag_info, property_list);
159 for (i = 0; i < sizeof(property_list)/sizeof(property_list[0]); i++)
161 if (!property_to_string(container, property_list[i].property_name, property_list[i].output))
163 WINE_ERR("Failed to retrieve property %s\n", wine_dbgstr_w(property_list[i].property_name));
164 return FALSE;
168 #ifdef _WIN64
169 system_info->win64 = TRUE;
170 #else
171 system_info->win64 = FALSE;
172 #endif
174 return TRUE;
177 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
179 static const struct information_fillers
181 const WCHAR *child_container_name;
182 BOOL (*fill_function)(IDxDiagContainer *, struct dxdiag_information *);
183 void (*free_function)(struct dxdiag_information *);
184 } filler_list[] =
186 {DxDiag_SystemInfo, fill_system_information, free_system_information},
189 void free_dxdiag_information(struct dxdiag_information *system_info)
191 size_t i;
193 if (!system_info)
194 return;
196 for (i = 0; i < sizeof(filler_list)/sizeof(filler_list[0]); i++)
197 filler_list[i].free_function(system_info);
199 HeapFree(GetProcessHeap(), 0, system_info);
202 struct dxdiag_information *collect_dxdiag_information(BOOL whql_check)
204 IDxDiagProvider *pddp = NULL;
205 IDxDiagContainer *root = NULL;
206 struct dxdiag_information *ret = NULL;
207 DXDIAG_INIT_PARAMS params = {sizeof(DXDIAG_INIT_PARAMS), DXDIAG_DX9_SDK_VERSION};
208 HRESULT hr;
209 size_t i;
211 /* Initialize the DxDiag COM instances. */
212 hr = CoCreateInstance(&CLSID_DxDiagProvider, NULL, CLSCTX_INPROC_SERVER,
213 &IID_IDxDiagProvider, (void **)&pddp);
214 if (FAILED(hr))
216 WINE_ERR("IDxDiagProvider instance creation failed with 0x%08x\n", hr);
217 goto error;
220 params.bAllowWHQLChecks = whql_check;
221 hr = IDxDiagProvider_Initialize(pddp, &params);
222 if (FAILED(hr))
223 goto error;
225 hr = IDxDiagProvider_GetRootContainer(pddp, &root);
226 if (FAILED(hr))
227 goto error;
229 ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
230 if (!ret)
231 goto error;
233 for (i = 0; i < sizeof(filler_list)/sizeof(filler_list[0]); i++)
235 IDxDiagContainer *child;
236 BOOL success;
238 hr = IDxDiagContainer_GetChildContainer(root, filler_list[i].child_container_name, &child);
239 if (FAILED(hr))
240 goto error;
242 success = filler_list[i].fill_function(child, ret);
243 IDxDiagContainer_Release(child);
244 if (!success)
245 goto error;
248 IDxDiagContainer_Release(root);
249 IDxDiagProvider_Release(pddp);
250 return ret;
252 error:
253 free_dxdiag_information(ret);
254 if (root) IDxDiagContainer_Release(root);
255 if (pddp) IDxDiagProvider_Release(pddp);
256 return NULL;