ReactOS  0.4.15-dev-2535-gcf6c191
system.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactX Diagnosis Application
3  * LICENSE: LGPL - See COPYING in the top level directory
4  * FILE: base/applications/dxdiag/system.c
5  * PURPOSE: ReactX diagnosis system page
6  * COPYRIGHT: Copyright 2008 Johannes Anderwald
7  *
8  */
9 
10 #include "precomp.h"
11 
13 
14 BOOL
16 {
17  HKEY hKey;
18  LONG res;
19  DWORD dwType;
20  DWORD dwSize;
21 
22  if (RegOpenKeyExW(hBaseKey, SubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
23  return FALSE;
24 
25  dwSize = Size;
28 
29  if (res != ERROR_SUCCESS)
30  return FALSE;
31 
32  if (dwType != Type)
33  return FALSE;
34 
35  if (Size == sizeof(DWORD))
36  return TRUE;
37 
38  Result[(Size / sizeof(WCHAR))-1] = L'\0';
39  return TRUE;
40 }
41 
42 
43 static
44 BOOL
46 {
47  WCHAR szVer[20];
48 
49  if (!GetRegValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", L"Version", REG_SZ, szVer, sizeof(szVer)))
50  return FALSE;
51 
52  if(!wcscmp(szVer, L"4.02.0095"))
53  wcscpy(szBuffer, L"1.0");
54  else if (!wcscmp(szVer, L"4.03.00.1096"))
55  wcscpy(szBuffer, L"2.0");
56  else if (!wcscmp(szVer, L"4.04.0068"))
57  wcscpy(szBuffer, L"3.0");
58  else if (!wcscmp(szVer, L"4.04.0069"))
59  wcscpy(szBuffer, L"3.0");
60  else if (!wcscmp(szVer, L"4.05.00.0155"))
61  wcscpy(szBuffer, L"5.0");
62  else if (!wcscmp(szVer, L"4.05.01.1721"))
63  wcscpy(szBuffer, L"5.0");
64  else if (!wcscmp(szVer, L"4.05.01.1998"))
65  wcscpy(szBuffer, L"5.0");
66  else if (!wcscmp(szVer, L"4.06.02.0436"))
67  wcscpy(szBuffer, L"6.0");
68  else if (!wcscmp(szVer, L"4.07.00.0700"))
69  wcscpy(szBuffer, L"7.0");
70  else if (!wcscmp(szVer, L"4.07.00.0716"))
71  wcscpy(szBuffer, L"7.0a");
72  else if (!wcscmp(szVer, L"4.08.00.0400"))
73  wcscpy(szBuffer, L"8.0");
74  else if (!wcscmp(szVer, L"4.08.01.0881"))
75  wcscpy(szBuffer, L"8.1");
76  else if (!wcscmp(szVer, L"4.08.01.0810"))
77  wcscpy(szBuffer, L"8.1");
78  else if (!wcscmp(szVer, L"4.09.0000.0900"))
79  wcscpy(szBuffer, L"9.0");
80  else if (!wcscmp(szVer, L"4.09.00.0900"))
81  wcscpy(szBuffer, L"9.0");
82  else if (!wcscmp(szVer, L"4.09.0000.0901"))
83  wcscpy(szBuffer, L"9.0a");
84  else if (!wcscmp(szVer, L"4.09.00.0901"))
85  wcscpy(szBuffer, L"9.0a");
86  else if (!wcscmp(szVer, L"4.09.0000.0902"))
87  wcscpy(szBuffer, L"9.0b");
88  else if (!wcscmp(szVer, L"4.09.00.0902"))
89  wcscpy(szBuffer, L"9.0b");
90  else if (!wcscmp(szVer, L"4.09.00.0904"))
91  wcscpy(szBuffer, L"9.0c");
92  else if (!wcscmp(szVer, L"4.09.0000.0904"))
93  wcscpy(szBuffer, L"9.0c");
94  else
95  return FALSE;
96 
97  return TRUE;
98 }
99 
101 {
102  SYSTEM_INFO archInfo;
103  ISWOW64PROC fnIsWow64Process;
104  BOOL isWow64 = FALSE;
105 
106  /* Find out if the program is running through WOW64 or not. Apparently,
107  IsWow64Process() is not available on all versions of Windows, so the function
108  has to be imported at runtime. If the function cannot be found, then assume
109  the program is not running in WOW64. */
110  fnIsWow64Process = (ISWOW64PROC)GetProcAddress(
111  GetModuleHandleW(L"kernel32"), "IsWow64Process");
112 
113  if (fnIsWow64Process != NULL)
114  fnIsWow64Process(GetCurrentProcess(), &isWow64);
115 
116  /* If the program is compiled as 32-bit, but is running in WOW64, it will
117  automatically report as 32-bit regardless of the actual system architecture.
118  It detects whether or not the program is using WOW64 or not, and then
119  uses GetNativeSystemInfo(). If it is, it will properly report the actual
120  system architecture to the user. */
121  if (isWow64)
122  GetNativeSystemInfo(&archInfo);
123  else
124  GetSystemInfo(&archInfo);
125 
126  /* Now check to see what the system architecture is */
128  {
129  switch(archInfo.wProcessorArchitecture)
130  {
132  {
133  wsprintfW(szBuffer, L"32-bit");
134  break;
135  }
137  {
138  wsprintfW(szBuffer, L"64-bit");
139  break;
140  }
142  {
143  wsprintfW(szBuffer, L"Itanium");
144  break;
145  }
147  {
148  wsprintfW(szBuffer, L"ARM");
149  break;
150  }
151  default:break;
152  }
153  }
154 }
155 
156 static
157 SIZE_T
159  BOOL UseSMBios,
160  PCHAR DmiString,
161  LPWSTR RegValue,
162  PVOID pBuf,
163  DWORD cchBuf,
164  BOOL bTrim)
165 {
166  SIZE_T Length = 0;
167  BOOL Result;
168 
169  if (UseSMBios)
170  {
171  Length = GetSMBiosStringW(DmiString, pBuf, cchBuf, bTrim);
172  }
173  if (Length == 0)
174  {
175  Result = GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", RegValue, REG_SZ, pBuf, cchBuf * sizeof(WCHAR));
176  if (Result)
177  {
178  Length = wcslen(pBuf);
179  }
180  }
181  return Length;
182 }
183 
184 static
185 VOID
187 {
188  WCHAR szTime[200];
189  WCHAR szOSName[50];
190  DWORD Length;
191  DWORDLONG AvailableBytes, UsedBytes;
192  MEMORYSTATUSEX mem;
193  WCHAR szFormat[50];
194  WCHAR szDesc[50];
195  SYSTEM_INFO SysInfo;
197  PVOID SMBiosBuf;
198  PCHAR DmiStrings[ID_STRINGS_MAX] = { 0 };
199  BOOL Result;
200 
201  /* set date/time */
202  szTime[0] = L'\0';
204  if (Length)
205  {
206  szTime[Length-1] = L',';
207  szTime[Length++] = L' ';
208  }
210  szTime[_countof(szTime)-1] = L'\0';
212 
213  /* set computer name */
214  szTime[0] = L'\0';
218 
219  /* set product name */
220  if (GetRegValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", REG_SZ, szOSName, sizeof(szOSName)))
221  {
222  if (LoadStringW(hInst, IDS_OS_VERSION, szFormat, _countof(szFormat)))
223  {
224  WCHAR szCpuName[50];
225 
228 
229  GetSystemCPU(szCpuName);
230 
232  {
233  szTime[_countof(szTime)-1] = L'\0';
236  }
237  else
238  {
239  /* If the version of the OS cannot be retrieved for some reason, then just give the OS Name and Architecture */
240  szTime[_countof(szTime)-1] = L'\0';
241  wsprintfW(szTime, L"%s %s", szOSName, szCpuName);
243  }
244  }
245  }
246  else
247  {
249  {
250  szTime[_countof(szTime)-1] = L'\0';
252  }
253  }
254 
255  /* FIXME set product language/local language */
258 
259  /* prepare SMBIOS data */
260  SMBiosBuf = LoadSMBiosData(DmiStrings);
261 
262  /* set system manufacturer */
263  szTime[0] = L'\0';
264  Length = GetBIOSValue(SMBiosBuf != NULL,
265  DmiStrings[SYS_VENDOR],
266  L"SystemManufacturer",
268  if (Length > 0)
269  {
270  szTime[_countof(szTime)-1] = L'\0';
272  }
273 
274  /* set motherboard model */
275  szTime[0] = L'\0';
276  Length = GetBIOSValue(SMBiosBuf != NULL,
277  DmiStrings[SYS_PRODUCT],
278  L"SystemProductName",
280  if (Length > 0)
281  {
283  }
284 
285  /* set bios model */
286  szTime[0] = L'\0';
287  Length = GetBIOSValue(SMBiosBuf != NULL,
288  DmiStrings[BIOS_VENDOR],
289  L"BIOSVendor",
291  if (Length > 0)
292  {
293  DWORD Index;
294  DWORD StrLength = _countof(szTime);
295 
296  Index = wcslen(szTime);
297  if (Index + 1 < _countof(szTime))
298  {
299  szTime[Index++] = L' ';
300  szTime[Index] = L'\0';
301  }
302  StrLength -= Index;
303 
304  Length = GetBIOSValue(SMBiosBuf != NULL,
305  DmiStrings[BIOS_DATE],
306  L"BIOSReleaseDate",
307  szTime + Index, StrLength, TRUE);
308  if (Length > 0)
309  {
310  if (Index + StrLength > _countof(szTime) - 15)
311  {
312  //FIXME retrieve BiosMajorRelease, BiosMinorRelease
313  //StrLength = wcslen(szTime + Index);
314  //szTime[Index+StrLength] = L' ';
315  //wcscpy(szTime + Index + StrLength, L"Ver: "); //FIXME NON-NLS
316  //szTime[_countof(szTime)-1] = L'\0';
317  }
319  }
320  }
321 
322  /* clean SMBIOS data */
323  FreeSMBiosData(SMBiosBuf);
324 
325  /* set processor string */
326  Result = GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\CentralProcessor\\0", L"ProcessorNameString", REG_SZ, szDesc, sizeof(szDesc));
327  if (!Result)
328  {
329  /* Processor Brand String not found */
330  /* FIXME: Implement CPU name detection routine */
331 
332  /* Finally try to use Identifier string */
333  Result = GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\CentralProcessor\\0", L"Identifier", REG_SZ, szDesc, sizeof(szDesc));
334  }
335  if (Result)
336  {
337  TrimDmiStringW(szDesc);
338  /* FIXME retrieve current speed */
339  szFormat[0] = L'\0';
340  GetSystemInfo(&SysInfo);
341  if (SysInfo.dwNumberOfProcessors > 1)
342  LoadStringW(hInst, IDS_FORMAT_MPPROC, szFormat, _countof(szFormat));
343  else
344  LoadStringW(hInst, IDS_FORMAT_UNIPROC, szFormat, _countof(szFormat));
345 
346  szFormat[_countof(szFormat)-1] = L'\0';
347  wsprintfW(szTime, szFormat, szDesc, SysInfo.dwNumberOfProcessors);
349  }
350 
351  /* retrieve available memory */
352  ZeroMemory(&mem, sizeof(mem));
353  mem.dwLength = sizeof(mem);
355  {
356  if (LoadStringW(hInst, IDS_FORMAT_MB, szFormat, _countof(szFormat)))
357  {
358  /* set total mem string */
359  szFormat[_countof(szFormat)-1] = L'\0';
360  wsprintfW(szTime, szFormat, (mem.ullTotalPhys/1048576));
362  }
363 
364  if (LoadStringW(hInst, IDS_FORMAT_SWAP, szFormat, _countof(szFormat)))
365  {
366  /* set swap string */
367  AvailableBytes = (mem.ullTotalPageFile-mem.ullTotalPhys)/1048576;
368  UsedBytes = (mem.ullTotalPageFile-mem.ullAvailPageFile)/1048576;
369 
370  szFormat[_countof(szFormat)-1] = L'\0';
371  wsprintfW(szTime, szFormat, (UsedBytes), (AvailableBytes));
373  }
374  }
375  /* set directx version string */
376  wcscpy(szTime, L"ReactX ");
377  if (GetDirectXVersion(szTime + 7))
378  {
380  }
381  else
382  {
384  {
385  szTime[_countof(szTime)-1] = L'\0';
387  }
388  }
389 }
390 
391 
394 {
397  switch (message)
398  {
399  case WM_INITDIALOG:
400  {
402  InitializeSystemPage(hDlg);
403  return TRUE;
404  }
405  }
406 
407  return FALSE;
408 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
static VOID InitializeSystemPage(HWND hwndDlg)
Definition: system.c:186
#define IDS_FORMAT_MPPROC
Definition: resource.h:114
signed char * PCHAR
Definition: retypes.h:7
#define IDC_STATIC_SWAP
Definition: resource.h:32
Definition: tftpd.h:59
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define IDS_OS_VERSION
Definition: resource.h:155
#define PROCESSOR_ARCHITECTURE_ARM
Definition: ketypes.h:110
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LOCALE_SLANGUAGE
Definition: winnls.h:26
TCHAR szTime[64]
Definition: solitaire.cpp:19
#define PROCESSOR_ARCHITECTURE_UNKNOWN
Definition: ketypes.h:115
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IDS_VERSION_UNKNOWN
Definition: resource.h:115
VOID WINAPI GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:206
#define IDC_STATIC_LANG
Definition: resource.h:26
#define IDC_STATIC_TIME
Definition: resource.h:23
#define CALLBACK
Definition: compat.h:35
#define GetLocaleInfo
Definition: winnls.h:1186
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ZeroMemory
Definition: winbase.h:1664
#define IDC_STATIC_BIOS
Definition: resource.h:29
#define IDC_STATIC_PROC
Definition: resource.h:30
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5817
#define SWP_NOZORDER
Definition: winuser.h:1232
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
int32_t INT_PTR
Definition: typedefs.h:64
SIZE_T GetSMBiosStringW(_In_ PCSTR DmiString, _Out_ PWSTR pBuf, _In_ DWORD cchBuf, _In_ BOOL bTrim)
Definition: udmihelp.c:145
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
TCHAR szOSName[50]
Definition: ver.c:29
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
#define PROCESSOR_ARCHITECTURE_IA64
Definition: ketypes.h:111
INT_PTR CALLBACK SystemPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: system.c:393
OSVERSIONINFOA OSVERSIONINFO
Definition: rtltypes.h:293
#define LOCALE_NOUSEROVERRIDE
Definition: winnls.h:19
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define IDC_STATIC_COMPUTER
Definition: resource.h:24
#define IDC_STATIC_VERSION
Definition: resource.h:33
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_STATIC_MANU
Definition: resource.h:27
BOOL * PBOOL
Definition: windef.h:161
#define WM_SETTEXT
Definition: winuser.h:1599
static BOOL GetDirectXVersion(WCHAR *szBuffer)
Definition: system.c:45
#define IDS_FORMAT_UNIPROC
Definition: resource.h:113
ULONG dwMajorVersion
Definition: rtltypes.h:247
#define IDC_STATIC_MODEL
Definition: resource.h:28
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ WDFCOLLECTION _In_ ULONG Index
#define SWP_NOACTIVATE
Definition: winuser.h:1227
#define _countof(array)
Definition: sndvol32.h:68
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
#define WINAPI
Definition: msvc.h:6
#define LOCALE_SYSTEM_DEFAULT
Type
Definition: Type.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID HANDLE
Definition: typedefs.h:73
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define PROCESSOR_ARCHITECTURE_AMD64
Definition: ketypes.h:114
ULONG dwBuildNumber
Definition: rtltypes.h:249
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
VOID GetSystemCPU(WCHAR *szBuffer)
Definition: system.c:100
#define GetCurrentProcess()
Definition: compat.h:618
#define PROCESSOR_ARCHITECTURE_INTEL
Definition: ketypes.h:105
#define SWP_NOSIZE
Definition: winuser.h:1230
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define IDS_FORMAT_MB
Definition: resource.h:111
HINSTANCE hInst
Definition: dxdiag.c:13
#define TIME_FORCE24HOURFORMAT
Definition: winnls.h:280
FxAutoRegKey hKey
#define GetDateFormat
Definition: winnls.h:1184
BOOL(WINAPI * ISWOW64PROC)(HANDLE, PBOOL)
Definition: system.c:12
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
VOID FreeSMBiosData(_In_ PVOID Buffer)
Definition: udmihelp.c:177
VOID TrimDmiStringW(_Inout_ PWSTR pStr)
Definition: udmihelp.c:110
#define DATE_LONGDATE
Definition: winnls.h:197
#define GetVersionEx
Definition: winbase.h:3708
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
static SIZE_T GetBIOSValue(BOOL UseSMBios, PCHAR DmiString, LPWSTR RegValue, PVOID pBuf, DWORD cchBuf, BOOL bTrim)
Definition: system.c:158
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
WORD wProcessorArchitecture
Definition: winbase.h:1151
ULONG dwMinorVersion
Definition: rtltypes.h:248
Definition: mem.c:156
unsigned long long DWORDLONG
Definition: intsafe.h:91
#define IDS_FORMAT_SWAP
Definition: resource.h:112
#define IDC_STATIC_OS
Definition: resource.h:25
DWORD dwNumberOfProcessors
Definition: winbase.h:1159
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
PVOID LoadSMBiosData(_Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
Definition: udmihelp.c:30
#define GetProcAddress(x, y)
Definition: compat.h:612
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static const RECT BP_PAINTPARAMS HDC *static const RECT *static BOOL
Definition: system.c:32
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1079
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size)
Definition: system.c:15
#define IDC_STATIC_MEM
Definition: resource.h:31
#define SWP_NOOWNERZORDER
Definition: winuser.h:1234
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22