Author: gedmurphy
Date: Wed Aug 1 01:17:57 2007
New Revision: 28056
URL:
http://svn.reactos.org/svn/reactos?rev=28056&view=rev
Log:
- don't write more bytes to the reg key than is required. fixes bug 2402
- use unicode explicitly
See issue #2402 for more details.
Modified:
trunk/reactos/dll/cpl/timedate/internettime.c
Modified: trunk/reactos/dll/cpl/timedate/internettime.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/internett…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/internettime.c (original)
+++ trunk/reactos/dll/cpl/timedate/internettime.c Wed Aug 1 01:17:57 2007
@@ -13,8 +13,8 @@
CreateNTPServerList(HWND hwnd)
{
HWND hList;
- TCHAR szValName[MAX_VALUE_NAME];
- TCHAR szData[256];
+ WCHAR szValName[MAX_VALUE_NAME];
+ WCHAR szData[256];
DWORD dwIndex = 0;
DWORD dwValSize;
DWORD dwNameSize;
@@ -25,8 +25,8 @@
hList = GetDlgItem(hwnd,
IDC_SERVERLIST);
- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers"),
+ lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
0,
KEY_QUERY_VALUE,
&hKey);
@@ -35,30 +35,30 @@
while (TRUE)
{
- dwValSize = MAX_VALUE_NAME * sizeof(TCHAR);
- szValName[0] = '\0';
- lRet = RegEnumValue(hKey,
- dwIndex,
- szValName,
- &dwValSize,
- NULL,
- NULL,
- (LPBYTE)szData,
- &dwNameSize);
+ dwValSize = MAX_VALUE_NAME * sizeof(WCHAR);
+ szValName[0] = L'\0';
+ lRet = RegEnumValueW(hKey,
+ dwIndex,
+ szValName,
+ &dwValSize,
+ NULL,
+ NULL,
+ (LPBYTE)szData,
+ &dwNameSize);
if (lRet == ERROR_SUCCESS)
{
/* get date from default reg value */
- if (_tcscmp(szValName, _T("")) == 0) // if (Index == 0)
+ if (wcscmp(szValName, L"") == 0) // if (Index == 0)
{
- dwDefault = _ttoi(szData);
+ dwDefault = _wtoi(szData);
dwIndex++;
}
else
{
- SendMessage(hList,
- CB_ADDSTRING,
- 0,
- (LPARAM)szData);
+ SendMessageW(hList,
+ CB_ADDSTRING,
+ 0,
+ (LPARAM)szData);
dwIndex++;
}
}
@@ -75,10 +75,10 @@
* combo boxes count from 0 */
dwDefault--;
- SendMessage(hList,
- CB_SETCURSEL,
- dwDefault,
- 0);
+ SendMessageW(hList,
+ CB_SETCURSEL,
+ dwDefault,
+ 0);
RegCloseKey(hKey);
}
@@ -91,13 +91,13 @@
HKEY hKey;
HWND hList;
UINT uSel;
- TCHAR szSel[4];
+ WCHAR szSel[4];
LONG lRet;
hList = GetDlgItem(hwnd,
IDC_SERVERLIST);
- uSel = (UINT)SendMessage(hList, CB_GETCURSEL, 0, 0);
+ uSel = (UINT)SendMessageW(hList, CB_GETCURSEL, 0, 0);
/* server reg entries count from 1,
* combo boxes count from 0 */
@@ -106,11 +106,11 @@
/* convert to wide char */
_itow(uSel, szSel, 10);
- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers"),
- 0,
- KEY_SET_VALUE,
- &hKey);
+ lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
+ 0,
+ KEY_SET_VALUE,
+ &hKey);
if (lRet != ERROR_SUCCESS)
{
DisplayWin32Error(lRet);
@@ -118,11 +118,11 @@
}
lRet = RegSetValueExW(hKey,
- _T(""),
+ L"",
0,
REG_SZ,
(LPBYTE)szSel,
- sizeof(szSel));
+ (wcslen(szSel) + 1) * sizeof(WCHAR));
if (lRet != ERROR_SUCCESS)
DisplayWin32Error(lRet);
@@ -132,43 +132,43 @@
/* get the domain name from the registry */
static BOOL
-GetNTPServerAddress(LPTSTR *lpAddress)
+GetNTPServerAddress(LPWSTR *lpAddress)
{
HKEY hKey;
- TCHAR szSel[4];
+ WCHAR szSel[4];
DWORD dwSize;
LONG lRet;
- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers"),
- 0,
- KEY_QUERY_VALUE,
- &hKey);
+ lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
+ 0,
+ KEY_QUERY_VALUE,
+ &hKey);
if (lRet != ERROR_SUCCESS)
goto fail;
/* Get data from default value */
- dwSize = 4 * sizeof(TCHAR);
- lRet = RegQueryValueEx(hKey,
- _T(""),
- NULL,
- NULL,
- (LPBYTE)szSel,
- &dwSize);
+ dwSize = 4 * sizeof(WCHAR);
+ lRet = RegQueryValueExW(hKey,
+ NULL,
+ NULL,
+ NULL,
+ (LPBYTE)szSel,
+ &dwSize);
if (lRet != ERROR_SUCCESS)
goto fail;
dwSize = 0;
- lRet = RegQueryValueEx(hKey,
- szSel,
- NULL,
- NULL,
- NULL,
- &dwSize);
- if (lRet != ERROR_SUCCESS)
- goto fail;
-
- (*lpAddress) = (LPTSTR)HeapAlloc(GetProcessHeap(),
+ lRet = RegQueryValueExW(hKey,
+ szSel,
+ NULL,
+ NULL,
+ NULL,
+ &dwSize);
+ if (lRet != ERROR_SUCCESS)
+ goto fail;
+
+ (*lpAddress) = (LPWSTR)HeapAlloc(GetProcessHeap(),
0,
dwSize);
if ((*lpAddress) == NULL)
@@ -177,12 +177,12 @@
goto fail;
}
- lRet = RegQueryValueEx(hKey,
- szSel,
- NULL,
- NULL,
- (LPBYTE)*lpAddress,
- &dwSize);
+ lRet = RegQueryValueExW(hKey,
+ szSel,
+ NULL,
+ NULL,
+ (LPBYTE)*lpAddress,
+ &dwSize);
if (lRet != ERROR_SUCCESS)
goto fail;
@@ -203,7 +203,7 @@
static ULONG
GetTimeFromServer(VOID)
{
- LPTSTR lpAddress = NULL;
+ LPWSTR lpAddress = NULL;
ULONG ulTime = 0;
if (GetNTPServerAddress(&lpAddress))
@@ -269,7 +269,7 @@
BOOL bChecked;
UINT uCheck;
- uCheck = (UINT)SendDlgItemMessage(hwnd, IDC_AUTOSYNC, BM_GETCHECK, 0, 0);
+ uCheck = (UINT)SendDlgItemMessageW(hwnd, IDC_AUTOSYNC, BM_GETCHECK, 0, 0);
bChecked = (uCheck == BST_CHECKED) ? TRUE : FALSE;
EnableWindow(GetDlgItem(hwnd, IDC_SERVERTEXT), bChecked);
@@ -284,25 +284,25 @@
GetSyncSetting(HWND hwnd)
{
HKEY hKey;
- TCHAR szData[8];
+ WCHAR szData[8];
DWORD dwSize;
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Parameters"),
- 0,
- KEY_QUERY_VALUE,
- &hKey) == ERROR_SUCCESS)
- {
- dwSize = 8 * sizeof(TCHAR);
- if (RegQueryValueEx(hKey,
- _T("Type"),
- NULL,
- NULL,
- (LPBYTE)szData,
- &dwSize) == ERROR_SUCCESS)
+ if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Parameters",
+ 0,
+ KEY_QUERY_VALUE,
+ &hKey) == ERROR_SUCCESS)
+ {
+ dwSize = 8 * sizeof(WCHAR);
+ if (RegQueryValueExW(hKey,
+ L"Type",
+ NULL,
+ NULL,
+ (LPBYTE)szData,
+ &dwSize) == ERROR_SUCCESS)
{
- if (_tcscmp(szData, _T("NTP")) == 0)
- SendDlgItemMessage(hwnd, IDC_AUTOSYNC, BM_SETCHECK, 0, 0);
+ if (wcscmp(szData, L"NTP") == 0)
+ SendDlgItemMessageW(hwnd, IDC_AUTOSYNC, BM_SETCHECK, 0, 0);
}
RegCloseKey(hKey);