Author: weiden
Date: Tue Oct 3 21:02:36 2006
New Revision: 24375
URL:
http://svn.reactos.org/svn/reactos?rev=24375&view=rev
Log:
Fix displaying Win32 errors (the Reg* APIs don't set the last error code!)
Modified:
trunk/reactos/dll/cpl/timedate/internettime.c
trunk/reactos/dll/cpl/timedate/ntpclient.c
trunk/reactos/dll/cpl/timedate/timedate.c
trunk/reactos/dll/cpl/timedate/timedate.h
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 Tue Oct 3 21:02:36 2006
@@ -116,7 +116,7 @@
&hKey);
if (Ret != ERROR_SUCCESS)
{
- GetError();
+ DisplayWin32Error(Ret);
return;
}
@@ -127,7 +127,7 @@
(LPBYTE)szSel,
sizeof(szSel));
if (Ret != ERROR_SUCCESS)
- GetError();
+ DisplayWin32Error(Ret);
RegCloseKey(hKey);
@@ -180,7 +180,10 @@
0,
dwSize);
if (buf == NULL)
+ {
+ Ret = ERROR_NOT_ENOUGH_MEMORY;
goto fail;
+ }
Ret = RegQueryValueExW(hKey,
szSel,
@@ -212,6 +215,7 @@
NULL,
NULL))
{
+ Ret = GetLastError();
goto fail;
}
@@ -223,7 +227,7 @@
return TRUE;
fail:
- GetError();
+ DisplayWin32Error(Ret);
if (hKey) RegCloseKey(hKey);
HeapFree(GetProcessHeap(), 0, buf);
HeapFree(GetProcessHeap(), 0, *lpAddress);
@@ -242,7 +246,7 @@
if (! GetNTPServerAddress(&lpAddress))
return 0;
- if (InitialiseConnection(lpAddress))
+ if (InitializeConnection(lpAddress))
{
if (SendData())
{
@@ -283,7 +287,7 @@
/* convert to a file time */
if (! SystemTimeToFileTime(&stNew, &ftNew))
{
- GetError();
+ DisplayWin32Error(GetLastError());
return;
}
@@ -295,7 +299,7 @@
/* convert back to a system time */
if (! FileTimeToSystemTime(&ftNew, &stNew))
{
- GetError();
+ DisplayWin32Error(GetLastError());
return;
}
@@ -304,7 +308,7 @@
I thought SetSystemTime already dealt
with this */
if (! SetSystemTime(&stNew))
- GetError();
+ DisplayWin32Error(GetLastError());
}
@@ -342,7 +346,7 @@
&hKey);
if (Ret != ERROR_SUCCESS)
{
- GetError();
+ DisplayWin32Error(Ret);
return;
}
@@ -355,7 +359,7 @@
&Size);
if (Ret != ERROR_SUCCESS)
{
- GetError();
+ DisplayWin32Error(Ret);
}
if (lstrcmp(Data, L"NTP") == 0)
@@ -369,7 +373,7 @@
static VOID
-InitialiseDialog(HWND hwnd)
+InitializeDialog(HWND hwnd)
{
GetSyncSetting(hwnd);
@@ -390,7 +394,7 @@
{
case WM_INITDIALOG:
{
- InitialiseDialog(hwndDlg);
+ InitializeDialog(hwndDlg);
}
break;
Modified: trunk/reactos/dll/cpl/timedate/ntpclient.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/ntpclient…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/ntpclient.c (original)
+++ trunk/reactos/dll/cpl/timedate/ntpclient.c Tue Oct 3 21:02:36 2006
@@ -15,7 +15,7 @@
SOCKADDR_IN myAddr, ntpAddr;
BOOL
-InitialiseConnection(LPSTR lpAddress)
+InitializeConnection(LPSTR lpAddress)
{
WSADATA wsaData;
HOSTENT *he;
Modified: trunk/reactos/dll/cpl/timedate/timedate.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/timedate.…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/timedate.c (original)
+++ trunk/reactos/dll/cpl/timedate/timedate.c Tue Oct 3 21:02:36 2006
@@ -22,22 +22,35 @@
{IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
};
-
-VOID GetError(VOID)
+#if DBG
+VOID DisplayWin32ErrorDbg(DWORD dwErrorCode, const char *file, int line)
+#else
+VOID DisplayWin32Error(DWORD dwErrorCode)
+#endif
{
LPVOID lpMsgBuf;
+#if DBG
+ TCHAR szMsg[255];
+#endif
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- GetLastError(),
+ dwErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );
- MessageBox(NULL, lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);
+#if DBG
+ if (_stprintf(szMsg, _T("%hs:%d: %s"), file, line, lpMsgBuf))
+ {
+ MessageBox(NULL, szMsg, NULL, MB_OK | MB_ICONERROR);
+ }
+#else
+ MessageBox(NULL, lpMsgBuf, NULL, MB_OK | MB_ICONERROR);
+#endif
LocalFree(lpMsgBuf);
}
Modified: trunk/reactos/dll/cpl/timedate/timedate.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/timedate/timedate.…
==============================================================================
--- trunk/reactos/dll/cpl/timedate/timedate.h (original)
+++ trunk/reactos/dll/cpl/timedate/timedate.h Tue Oct 3 21:02:36 2006
@@ -42,7 +42,12 @@
/* timedate.c */
-VOID GetError(VOID);
+#if DBG
+VOID DisplayWin32ErrorDbg(DWORD dwErrorCode, const char *file, int line);
+#define DisplayWin32Error(e) DisplayWin32ErrorDbg(e, __FILE__, __LINE__);
+#else
+VOID DisplayWin32Error(DWORD dwErrorCode);
+#endif
/* clock.c */
@@ -51,7 +56,7 @@
/* ntpclient.c */
-BOOL InitialiseConnection(CHAR *szIpAddr);
+BOOL InitializeConnection(CHAR *szIpAddr);
VOID DestroyConnection(VOID);
BOOL SendData(VOID);
ULONG RecieveData(VOID);