* 2: Horizontal splitting.
*/
-HWND hwndMainWindow; /* Main window */
+HWND hwndMainWindow = NULL; /* Main window */
HWND hwndTreeView; /* TreeView control */
HWND hwndListView; /* ListView control */ // NOTE: Used by evtdetctl.c
HWND hwndEventDetails; /* Event details pane */
/* Global event records cache for the current active event log filter */
DWORD g_TotalRecords = 0;
-PEVENTLOGRECORD *g_RecordPtrs = NULL;
+PEVENTLOGRECORD* g_RecordPtrs = NULL;
/* Lists of event logs and event log filters */
LIST_ENTRY EventLogList;
INT_PTR CALLBACK EventDetails(HWND, UINT, WPARAM, LPARAM);
+/* MAIN FUNCTIONS *************************************************************/
+
+VOID
+ShowWin32Error(IN DWORD dwError)
+{
+ LPWSTR lpMessageBuffer;
+
+ if (dwError == ERROR_SUCCESS)
+ return;
+
+ if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ LANG_USER_DEFAULT,
+ (LPWSTR)&lpMessageBuffer,
+ 0, NULL))
+ {
+ return;
+ }
+
+ MessageBoxW(hwndMainWindow, lpMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
+ LocalFree(lpMessageBuffer);
+}
+
int APIENTRY
wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
msg.wParam = (WPARAM)-1;
+ /* Store the instance handle in the global variable */
+ hInst = hInstance;
+
/* Initialize global strings */
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, ARRAYSIZE(szTitle));
LoadStringW(hInstance, IDS_APP_TITLE_EX, szTitleTemplate, ARRAYSIZE(szTitleTemplate));
/* GENERIC HELPER FUNCTIONS ***************************************************/
-VOID
-ShowLastWin32Error(VOID)
-{
- DWORD dwError;
- LPWSTR lpMessageBuffer;
-
- dwError = GetLastError();
- if (dwError == ERROR_SUCCESS)
- return;
-
- if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- LANG_USER_DEFAULT,
- (LPWSTR)&lpMessageBuffer,
- 0, NULL))
- {
- return;
- }
-
- MessageBoxW(hwndMainWindow, lpMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
- LocalFree(lpMessageBuffer);
-}
-
VOID
EventTimeToSystemTime(IN DWORD EventTime,
OUT PSYSTEMTIME pSystemTime)
while ((pTempMessage = wcschr(pTempMessage, L'%')))
{
pTempMessage++;
- if (isdigit(*pTempMessage))
+ if (iswdigit(*pTempMessage))
{
dwParamCount++;
- while (isdigit(*++pTempMessage)) ;
+ while (iswdigit(*++pTempMessage)) ;
}
}
}
while ((pTempMessage = wcsstr(pTempMessage, L"%%")))
{
pTempMessage += 2;
- if (isdigit(*pTempMessage))
+ if (iswdigit(*pTempMessage))
{
dwParamCount++;
- while (isdigit(*++pTempMessage)) ;
+ while (iswdigit(*++pTempMessage)) ;
}
}
}
while ((pTempMessage = wcschr(pTempMessage, L'%')) && (i < dwParamCount))
{
pTempMessage++;
- if (isdigit(*pTempMessage))
+ if (iswdigit(*pTempMessage))
{
pParamData[i].pStartingAddress = pTempMessage-1;
pParamData[i].pParameterID = (DWORD)_wtol(pTempMessage);
- while (isdigit(*++pTempMessage)) ;
+ while (iswdigit(*++pTempMessage)) ;
pParamData[i].pEndingAddress = pTempMessage;
i++;
while ((pTempMessage = wcsstr(pTempMessage, L"%%")) && (i < dwParamCount))
{
pTempMessage += 2;
- if (isdigit(*pTempMessage))
+ if (iswdigit(*pTempMessage))
{
pParamData[i].pStartingAddress = pTempMessage-2;
pParamData[i].pParameterID = (DWORD)_wtol(pTempMessage);
- while (isdigit(*++pTempMessage)) ;
+ while (iswdigit(*++pTempMessage)) ;
pParamData[i].pEndingAddress = pTempMessage;
i++;
EventLog->LogName = HeapAlloc(GetProcessHeap(), 0, cchName * sizeof(WCHAR));
if (!EventLog->LogName)
{
+ if (EventLog->ComputerName)
+ HeapFree(GetProcessHeap(), 0, EventLog->ComputerName);
HeapFree(GetProcessHeap(), 0, EventLog);
return NULL;
}
if (EventLog->LogName)
HeapFree(GetProcessHeap(), 0, EventLog->LogName);
+ if (EventLog->ComputerName)
+ HeapFree(GetProcessHeap(), 0, EventLog->ComputerName);
+
if (EventLog->FileName)
HeapFree(GetProcessHeap(), 0, EventLog->FileName);
lpMsgBuf = szMessage;
while ((lpMsgBuf = wcsstr(lpMsgBuf, L"%%")))
{
- if (isdigit(lpMsgBuf[2]))
+ if (iswdigit(lpMsgBuf[2]))
{
RtlMoveMemory(lpMsgBuf, lpMsgBuf+1, ((szStringArray + cch) - lpMsgBuf - 1) * sizeof(WCHAR));
}
if (hEventLog == NULL)
{
- ShowLastWin32Error();
+ ShowWin32Error(GetLastError());
goto Cleanup;
}
g_RecordPtrs = HeapAlloc(hProcessHeap, HEAP_ZERO_MEMORY, dwTotalRecords * sizeof(*g_RecordPtrs));
if (!g_RecordPtrs)
{
- // ShowLastWin32Error();
+ // ShowWin32Error(GetLastError());
goto Quit;
}
g_TotalRecords = dwTotalRecords;
VOID
-OpenUserEventLog(VOID)
+OpenUserEventLogFile(IN LPCWSTR lpszFileName)
{
+ WIN32_FIND_DATAW FindData;
+ HANDLE hFind;
PEVENTLOG EventLog;
PEVENTLOGFILTER EventLogFilter;
+ SIZE_T cchFileName;
HTREEITEM hItem = NULL;
- WCHAR szFileName[MAX_PATH];
- ZeroMemory(szFileName, sizeof(szFileName));
-
- sfn.lpstrFile = szFileName;
- sfn.nMaxFile = ARRAYSIZE(szFileName);
-
- if (!GetOpenFileNameW(&sfn))
+ /* Check whether the file actually exists */
+ hFind = FindFirstFileW(lpszFileName, &FindData);
+ if (hFind == INVALID_HANDLE_VALUE)
+ {
+ ShowWin32Error(GetLastError());
return;
- sfn.lpstrFile[sfn.nMaxFile-1] = UNICODE_NULL;
+ }
+ FindClose(hFind);
/* Allocate a new event log entry */
- EventLog = AllocEventLog(NULL, sfn.lpstrFile, FALSE);
+ EventLog = AllocEventLog(NULL, lpszFileName, FALSE);
if (EventLog == NULL)
+ {
+ ShowWin32Error(ERROR_NOT_ENOUGH_MEMORY);
return;
+ }
/* Allocate a new event log filter entry for this event log */
EventLogFilter = AllocEventLogFilter(// LogName,
1, &EventLog);
if (EventLogFilter == NULL)
{
- HeapFree(GetProcessHeap(), 0, EventLog);
+ ShowWin32Error(ERROR_NOT_ENOUGH_MEMORY);
+ EventLog_Free(EventLog);
return;
}
InsertTailList(&EventLogFilterList, &EventLogFilter->ListEntry);
/* Retrieve and cache the event log file */
- EventLog->FileName = HeapAlloc(GetProcessHeap(), 0, sfn.nMaxFile * sizeof(WCHAR));
+ cchFileName = wcslen(lpszFileName) + 1;
+ EventLog->FileName = HeapAlloc(GetProcessHeap(), 0, cchFileName * sizeof(WCHAR));
if (EventLog->FileName)
- StringCchCopyW(EventLog->FileName, sfn.nMaxFile, sfn.lpstrFile);
+ StringCchCopyW(EventLog->FileName, cchFileName, lpszFileName);
hItem = TreeViewAddItem(hwndTreeView, htiUserLogs,
- szFileName,
+ (LPWSTR)lpszFileName,
2, 3, (LPARAM)EventLogFilter);
/* Select the event log */
TreeView_SelectItem(hwndTreeView, hItem);
TreeView_EnsureVisible(hwndTreeView, hItem);
}
+ InvalidateRect(hwndTreeView, NULL, FALSE);
SetFocus(hwndTreeView);
}
+VOID
+OpenUserEventLog(VOID)
+{
+ WCHAR szFileName[MAX_PATH];
+
+ ZeroMemory(szFileName, sizeof(szFileName));
+
+ sfn.lpstrFile = szFileName;
+ sfn.nMaxFile = ARRAYSIZE(szFileName);
+
+ if (!GetOpenFileNameW(&sfn))
+ return;
+ sfn.lpstrFile[sfn.nMaxFile-1] = UNICODE_NULL;
+
+ OpenUserEventLogFile(sfn.lpstrFile);
+}
+
VOID
SaveEventLog(IN PEVENTLOGFILTER EventLogFilter)
{
if (!hEventLog)
{
- ShowLastWin32Error();
+ ShowWin32Error(GetLastError());
return;
}
if (!BackupEventLogW(hEventLog, szFileName))
- ShowLastWin32Error();
+ ShowWin32Error(GetLastError());
CloseEventLog(hEventLog);
}
// // TreeView_Expand(hwndTreeView, htiUserLogs, TVE_EXPAND);
// TreeView_SelectItem(hwndTreeView, hItem);
// TreeView_EnsureVisible(hwndTreeView, hItem);
+ InvalidateRect(hwndTreeView, NULL, FALSE);
SetFocus(hwndTreeView);
}
if (!hEventLog)
{
- ShowLastWin32Error();
+ ShowWin32Error(GetLastError());
return FALSE;
}
Success = ClearEventLogW(hEventLog, sfn.lpstrFile);
if (!Success)
- ShowLastWin32Error();
+ ShowWin32Error(GetLastError());
CloseEventLog(hEventLog);
return Success;
1, &EventLog);
if (EventLogFilter == NULL)
{
- HeapFree(GetProcessHeap(), 0, EventLog);
+ EventLog_Free(EventLog);
continue;
}
TreeView_SelectItem(hwndTreeView, hItemDefault);
TreeView_EnsureVisible(hwndTreeView, hItemDefault);
}
+ InvalidateRect(hwndTreeView, NULL, FALSE);
SetFocus(hwndTreeView);
return;
LVCOLUMNW lvc = {0};
WCHAR szTemp[256];
- hInst = hInstance; // Store instance handle in our global variable
-
/* Create the main window */
hwndMainWindow = CreateWindowW(szWindowClass,
szTitle,