Author: janderwald
Date: Sun Apr 20 03:48:55 2008
New Revision: 33050
URL: 
http://svn.reactos.org/svn/reactos?rev=33050&view=rev
Log:
- avoid using BringWindowToTop as it creates display problems
- build a custom function GetRegValue to allow dxdiag be used on older Windows versions
- try to fix potential buffer overflows
Modified:
    trunk/reactos/base/applications/dxdiag/dxdiag.c
    trunk/reactos/base/applications/dxdiag/precomp.h
    trunk/reactos/base/applications/dxdiag/system.c
Modified: trunk/reactos/base/applications/dxdiag/dxdiag.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/dxdiag/d…
==============================================================================
--- trunk/reactos/base/applications/dxdiag/dxdiag.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/dxdiag/dxdiag.c [iso-8859-1] Sun Apr 20 03:48:55 2008
@@ -66,9 +66,6 @@
          else
              ShowWindow(pContext->hDialogs[Index], SW_HIDE);
     }
-
-    /* make sure its displayed */
-    BringWindowToTop(pContext->hDialogs[CurSel]);
 }
@@ -190,7 +187,7 @@
     UNREFERENCED_PARAMETER(nCmdShow);
     InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
-    InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES;
+    InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES | ICC_STANDARD_CLASSES;
     InitCommonControlsEx(&InitControls);
     hInst = hInstance;
Modified: trunk/reactos/base/applications/dxdiag/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/dxdiag/p…
==============================================================================
--- trunk/reactos/base/applications/dxdiag/precomp.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/dxdiag/precomp.h [iso-8859-1] Sun Apr 20 03:48:55 2008
@@ -4,7 +4,6 @@
 #include <stdio.h>
 #include <windows.h>
 #include <commctrl.h>
-
 #include "resource.h"
 typedef struct
@@ -27,6 +26,7 @@
 INT_PTR CALLBACK InputPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
lParam);
 INT_PTR CALLBACK HelpPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
+BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR
Result, DWORD Size);
 #endif
Modified: trunk/reactos/base/applications/dxdiag/system.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/dxdiag/s…
==============================================================================
--- trunk/reactos/base/applications/dxdiag/system.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/dxdiag/system.c [iso-8859-1] Sun Apr 20 03:48:55 2008
@@ -9,14 +9,40 @@
 #include "precomp.h"
+BOOL
+GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result,
DWORD Size)
+{
+    HKEY hKey;
+    LONG res;
+    DWORD dwType;
+    DWORD dwSize;
+
+
+    if (RegOpenKeyExW(hBaseKey, SubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
+        return FALSE;
+
+    dwSize = Size;
+    res = RegQueryValueExW(hKey, ValueName, NULL, &dwType, (LPBYTE)Result,
&dwSize);
+    RegCloseKey(hKey);
+
+    if (dwType != Type)
+        return FALSE;
+
+    if (res != ERROR_SUCCESS)
+        return FALSE;
+
+    Result[(Size / sizeof(WCHAR))-1] = L'\0';
+    return TRUE;
+}
+
+
 static
 BOOL
 GetDirectXVersion(WCHAR * szBuffer)
 {
     WCHAR szVer[20];
-    DWORD dwVer = sizeof(szVer);
-
-    if (RegGetValueW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX",
L"Version", RRF_RT_REG_SZ, NULL, szVer, &dwVer) != ERROR_SUCCESS)
+
+    if (!GetRegValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX",
L"Version", REG_SZ, szVer, sizeof(szVer)))
         return FALSE;
     if(!wcscmp(szVer, L"4.02.0095"))
@@ -218,8 +244,7 @@
     /* set system manufacturer */
     szTime[0] = L'\0';
-    Length = sizeof(szTime) / sizeof(WCHAR);
-    if (RegGetValueW(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\BIOS", L"SystemManufacturer",
RRF_RT_REG_SZ, NULL, szTime, &Length) == ERROR_SUCCESS)
+    if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS",
L"SystemManufacturer", REG_SZ, szTime, sizeof(szTime)))
     {
         szTime[199] = L'\0';
         SendDlgItemMessageW(hwndDlg, IDC_STATIC_MANU, WM_SETTEXT, 0, (LPARAM)szTime);
@@ -227,37 +252,36 @@
     /* set motherboard model */
     szTime[0] = L'\0';
-    Length = sizeof(szTime) / sizeof(WCHAR);
-    if (RegGetValueW(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\BIOS", L"SystemProductName",
RRF_RT_REG_SZ, NULL, szTime, &Length) == ERROR_SUCCESS)
-    {
-        szTime[199] = L'\0';
+    if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS",
L"SystemProductName", REG_SZ, szTime, sizeof(szTime)))
+    {
         SendDlgItemMessageW(hwndDlg, IDC_STATIC_MODEL, WM_SETTEXT, 0, (LPARAM)szTime);
     }
     /* set bios model */
     szTime[0] = L'\0';
-    Length = sizeof(szTime) / sizeof(WCHAR);
-    if (RegGetValueW(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\BIOS", L"BIOSVendor", RRF_RT_REG_SZ,
NULL, szTime, &Length) == ERROR_SUCCESS)
+    if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS",
L"BIOSVendor", REG_SZ, szTime, sizeof(szTime)))
     {
         DWORD Index;
-        DWORD StrLength = (sizeof(szTime) / sizeof(WCHAR)) - (Length/sizeof(WCHAR));
-
-        Index = (Length/sizeof(WCHAR));
-        szTime[Index-1] = L' ';
-
-        if (RegGetValueW(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\BIOS", L"BIOSReleaseDate",
RRF_RT_REG_SZ, NULL, &szTime[Index], &StrLength) == ERROR_SUCCESS)
-        {
-            StrLength = (StrLength/sizeof(WCHAR));
-        }
-        szTime[Index+StrLength] = L' ';
-        wcscpy(&szTime[Index+StrLength], L"Ver: "); //FIXME NON-NLS
-        szTime[199] = L'\0';
-        SendDlgItemMessageW(hwndDlg, IDC_STATIC_BIOS, WM_SETTEXT, 0, (LPARAM)szTime);
-        //FIXME  retrieve BiosMajorRelease, BiosMinorRelease
+        DWORD StrLength = (sizeof(szTime) / sizeof(WCHAR));
+
+        Index = wcslen(szTime);
+        StrLength -= Index;
+
+        if (GetRegValue(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\BIOS", L"BIOSReleaseDate", REG_SZ,
&szTime[Index], StrLength))
+        {
+            if (Index + StrLength > (sizeof(szTime)/sizeof(WCHAR))- 15)
+            {
+                //FIXME  retrieve BiosMajorRelease, BiosMinorRelease
+                //StrLength = wcslen(&szTime[Index]);
+                //szTime[Index+StrLength] = L' ';
+                //wcscpy(&szTime[Index+StrLength], L"Ver: "); //FIXME
NON-NLS
+                //szTime[(sizeof(szTime)/sizeof(WCHAR))-1] = L'\0';
+            }
+            SendDlgItemMessageW(hwndDlg, IDC_STATIC_BIOS, WM_SETTEXT, 0, (LPARAM)szTime);
+        }
     }
     /* set processor string */
-    Length = sizeof(szDesc);
-    if (RegGetValueW(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\CentralProcessor\\0",
L"ProcessorNameString", RRF_RT_REG_SZ, NULL, szDesc, &Length) ==
ERROR_SUCCESS)
+    if (GetRegValue(HKEY_LOCAL_MACHINE,
L"Hardware\\Description\\System\\CentralProcessor\\0",
L"ProcessorNameString", REG_SZ, szDesc, sizeof(szDesc)))
     {
         /* FIXME retrieve current speed */
         szFormat[0] = L'\0';