msvcp90: Added _Stofx implementation.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob0c88ad5629e8bf071ec81189e7385e89dcf65117
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wbemcli.h"
29 #include "tlhelp32.h"
31 #include "wine/debug.h"
32 #include "wbemprox_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
36 static const WCHAR class_biosW[] =
37 {'W','i','n','3','2','_','B','I','O','S',0};
38 static const WCHAR class_compsysW[] =
39 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
40 static const WCHAR class_osW[] =
41 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
42 static const WCHAR class_processW[] =
43 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
44 static const WCHAR class_processorW[] =
45 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
47 static const WCHAR prop_captionW[] =
48 {'C','a','p','t','i','o','n',0};
49 static const WCHAR prop_commandlineW[] =
50 {'C','o','m','m','a','n','d','L','i','n','e',0};
51 static const WCHAR prop_descriptionW[] =
52 {'D','e','s','c','r','i','p','t','i','o','n',0};
53 static const WCHAR prop_handleW[] =
54 {'H','a','n','d','l','e',0};
55 static const WCHAR prop_manufacturerW[] =
56 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
57 static const WCHAR prop_modelW[] =
58 {'M','o','d','e','l',0};
59 static const WCHAR prop_osarchitectureW[] =
60 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
61 static const WCHAR prop_pprocessidW[] =
62 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
63 static const WCHAR prop_processidW[] =
64 {'P','r','o','c','e','s','s','I','D',0};
65 static const WCHAR prop_releasedateW[] =
66 {'R','e','l','e','a','s','e','D','a','t','e',0};
67 static const WCHAR prop_serialnumberW[] =
68 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
69 static const WCHAR prop_threadcountW[] =
70 {'T','h','r','e','a','d','C','o','u','n','t',0};
72 static const struct column col_bios[] =
74 { prop_descriptionW, CIM_STRING },
75 { prop_manufacturerW, CIM_STRING },
76 { prop_releasedateW, CIM_DATETIME },
77 { prop_serialnumberW, CIM_STRING }
79 static const struct column col_compsys[] =
81 { prop_descriptionW, CIM_STRING },
82 { prop_manufacturerW, CIM_STRING },
83 { prop_modelW, CIM_STRING }
85 static const struct column col_os[] =
87 { prop_captionW, CIM_STRING },
88 { prop_osarchitectureW, CIM_STRING }
90 static const struct column col_process[] =
92 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
93 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
94 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
95 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
96 { prop_pprocessidW, CIM_UINT32 },
97 { prop_processidW, CIM_UINT32 },
98 { prop_threadcountW, CIM_UINT32 }
100 static const struct column col_processor[] =
102 { prop_manufacturerW, CIM_STRING }
105 static const WCHAR bios_descriptionW[] =
106 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
107 static const WCHAR bios_manufacturerW[] =
108 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
109 static const WCHAR bios_releasedateW[] =
110 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
111 static const WCHAR bios_serialnumberW[] =
112 {'0',0};
113 static const WCHAR compsys_descriptionW[] =
114 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
115 static const WCHAR compsys_manufacturerW[] =
116 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
117 static const WCHAR compsys_modelW[] =
118 {'W','i','n','e',0};
119 static const WCHAR os_captionW[] =
120 {'W','i','n','e',0};
121 static const WCHAR os_32bitW[] =
122 {'3','2','-','b','i','t',0};
123 static const WCHAR os_64bitW[] =
124 {'6','4','-','b','i','t',0};
125 static const WCHAR processor_manufacturerW[] =
126 {'G','e','n','u','i','n','e','I','n','t','e','l',0};
128 #include "pshpack1.h"
129 struct record_bios
131 const WCHAR *description;
132 const WCHAR *manufacturer;
133 const WCHAR *releasedate;
134 const WCHAR *serialnumber;
136 struct record_computersystem
138 const WCHAR *description;
139 const WCHAR *manufacturer;
140 const WCHAR *model;
142 struct record_operatingsystem
144 const WCHAR *caption;
145 const WCHAR *osarchitecture;
147 struct record_process
149 const WCHAR *caption;
150 const WCHAR *commandline;
151 const WCHAR *description;
152 const WCHAR *handle;
153 UINT32 pprocess_id;
154 UINT32 process_id;
155 UINT32 thread_count;
157 struct record_processor
159 const WCHAR *manufacturer;
161 #include "poppack.h"
163 static const struct record_bios data_bios[] =
165 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
167 static const struct record_computersystem data_compsys[] =
169 { compsys_descriptionW, compsys_manufacturerW, compsys_modelW }
171 static const struct record_processor data_processor[] =
173 { processor_manufacturerW }
176 static WCHAR *get_cmdline( DWORD process_id )
178 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
179 return NULL; /* FIXME handle different process case */
182 static void fill_process( struct table *table )
184 static const WCHAR fmtW[] = {'%','u',0};
185 WCHAR handle[11];
186 struct record_process *rec;
187 PROCESSENTRY32W entry;
188 HANDLE snap;
189 UINT num_rows = 0, offset = 0, count = 8;
191 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
192 if (snap == INVALID_HANDLE_VALUE) return;
194 entry.dwSize = sizeof(entry);
195 if (!Process32FirstW( snap, &entry )) goto done;
196 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
200 if (num_rows > count)
202 BYTE *data;
203 count *= 2;
204 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
205 table->data = data;
207 rec = (struct record_process *)(table->data + offset);
208 rec->caption = heap_strdupW( entry.szExeFile );
209 rec->commandline = get_cmdline( entry.th32ProcessID );
210 rec->description = heap_strdupW( entry.szExeFile );
211 sprintfW( handle, fmtW, entry.th32ProcessID );
212 rec->handle = heap_strdupW( handle );
213 rec->process_id = entry.th32ProcessID;
214 rec->pprocess_id = entry.th32ParentProcessID;
215 rec->thread_count = entry.cntThreads;
216 offset += sizeof(*rec);
217 num_rows++;
218 } while (Process32NextW( snap, &entry ));
220 TRACE("created %u rows\n", num_rows);
221 table->num_rows = num_rows;
223 done:
224 CloseHandle( snap );
227 static void fill_os( struct table *table )
229 struct record_operatingsystem *rec;
230 SYSTEM_INFO info;
232 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
234 rec = (struct record_operatingsystem *)table->data;
235 rec->caption = os_captionW;
237 GetNativeSystemInfo( &info );
238 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
239 rec->osarchitecture = os_64bitW;
240 else
241 rec->osarchitecture = os_32bitW;
243 TRACE("created 1 row\n");
244 table->num_rows = 1;
247 static struct table classtable[] =
249 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios, NULL },
250 { class_compsysW, SIZEOF(col_compsys), col_compsys, SIZEOF(data_compsys), (BYTE *)data_compsys, NULL },
251 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
252 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
253 { class_processorW, SIZEOF(col_processor), col_processor, SIZEOF(data_processor), (BYTE *)data_processor, NULL }
256 struct table *get_table( const WCHAR *name )
258 UINT i;
259 struct table *table = NULL;
261 for (i = 0; i < SIZEOF(classtable); i++)
263 if (!strcmpiW( classtable[i].name, name ))
265 table = &classtable[i];
266 if (table->fill && !table->data) table->fill( table );
267 break;
270 return table;