#include #include void DisplayError(DWORD dwError); int main(int argc, char** argv) { HANDLE hf; DWORD dwLogCount; DWORD dwLogSize, dwReadByte, dwNextSize, dwError; EVENTLOGRECORD* pEventLogRecord = NULL; BOOL bResult; hf = OpenEventLogW(NULL, L"System"); if (hf == NULL) { printf("Event Log Open Error.\n"); return -1; } if (GetNumberOfEventLogRecords(hf, &dwLogCount)) printf("Event Log Count %d\n", dwLogCount); else printf("Could not get Event Log Count\n"); dwLogSize = 1024; pEventLogRecord = (EVENTLOGRECORD*)GlobalAlloc(GPTR, dwLogSize); if (pEventLogRecord == NULL) { printf("Memory Allocation Error\n"); CloseEventLog(hf); return -1; } bResult = ReadEventLogW(hf, EVENTLOG_FORWARDS_READ | EVENTLOG_SEQUENTIAL_READ, 0, pEventLogRecord, dwLogSize, &dwReadByte, &dwNextSize); if (bResult) { printf("ReadByte : %d\n", dwReadByte); } else { dwError = GetLastError(); DisplayError(dwError); } if (pEventLogRecord != NULL) { GlobalFree(pEventLogRecord); } CloseEventLog(hf); return 0; } void DisplayError(DWORD dwError) { LPTSTR lpBuffer; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, LANG_USER_DEFAULT, (LPTSTR)&lpBuffer, 0, NULL); printf("%s\n", (char*)lpBuffer); LocalFree(lpBuffer); }