例子:<br>void DisplayEntries( )<br>{<br> HANDLE h;<br> EVENTLOGRECORD *pevlr; <br> BYTE bBuffer[BUFFER_SIZE]; <br> DWORD dwRead, dwNeeded, cRecords, dwThisRecord; <br> <br> // Open the Application event log. <br> h = OpenEventLog( NULL, // use local computer<br> "Application"); // source name<br> if (h == NULL) <br> ErrorExit("Could not open the Application event log."); <br> <br> pevlr = (EVENTLOGRECORD *) &bBuffer; <br> <br> // Get the record number of the oldest event log record.<br><br> GetOldestEventLogRecord(h, &dwThisRecord);<br><br> // Opening the event log positions the file pointer for this <br> // handle at the beginning of the log. Read the event log records <br> // sequentially until the last record has been read. <br> <br> while (ReadEventLog(h, // event log handle <br> EVENTLOG_FORWARDS_READ | // reads forward <br> EVENTLOG_SEQUENTIAL_READ, // sequential read <br> 0, // ignored for sequential reads <br> pevlr, // pointer to buffer <br> BUFFER_SIZE, // size of buffer <br> &dwRead, // number of bytes read <br> &dwNeeded)) // bytes in next record <br> {<br> while (dwRead > 0) <br> { <br> // Print the record number, event identifier, type, <br> // and source name. <br> <br> printf("%02d Event ID: 0x%08X ", <br> dwThisRecord++, pevlr->EventID); <br> printf("EventType: %d Source: %s/n", <br> pevlr->EventType, (LPSTR) ((LPBYTE) pevlr + <br> sizeof(EVENTLOGRECORD))); <br> <br> dwRead -= pevlr->Length; <br> pevlr = (EVENTLOGRECORD *) <br> ((LPBYTE) pevlr + pevlr->Length); <br> } <br> <br> pevlr = (EVENTLOGRECORD *) &bBuffer; <br> } <br> <br> CloseEventLog(h); <br>} <br>