★★★★★关于ReadEventLog函数的使用---在线等待(20分)

  • 主题发起人 主题发起人 thygw
  • 开始时间 开始时间
T

thygw

Unregistered / Unconfirmed
GUEST, unregistred user!
强烈要求给一个例子,如有答案,小弟不胜感激![:)]
 
???????????????????????????????????????
 
ReadEventLog<br>The ReadEventLog function reads a whole number of entries from the specified event log. The function can be used to read log entries in chronological or reverse chronological order. <br><br>BOOL ReadEventLog(<br>&nbsp; HANDLE hEventLog, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// handle to event log<br>&nbsp; DWORD dwReadFlags, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // how to read log<br>&nbsp; DWORD dwRecordOffset, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// initial record offset<br>&nbsp; LPVOID lpBuffer, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // buffer for read data<br>&nbsp; DWORD nNumberOfBytesToRead, &nbsp; &nbsp; &nbsp;// bytes to read<br>&nbsp; DWORD *pnBytesRead, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// number of bytes read<br>&nbsp; DWORD *pnMinNumberOfBytesNeeded &nbsp;// bytes required<br>);<br>Parameters<br>hEventLog <br>[in] Handle to the event log to read. This handle is returned by the OpenEventLog function. <br>dwReadFlags <br>[in] Specifies how the read operation is to proceed. This parameter must include one of the following values. Value Meaning <br>EVENTLOG_SEEK_READ The read operation proceeds from the record specified by the dwRecordOffset parameter. <br>This flag cannot be used with EVENTLOG_SEQUENTIAL_READ.<br>&nbsp;<br>EVENTLOG_SEQUENTIAL_READ The read operation proceeds sequentially from the last call to the ReadEventLog function using this handle. <br>This flag cannot be used with EVENTLOG_SEEK_READ.<br><br>If the buffer is large enough, more than one record can be read at the specified seek position; you must specify one of the following flags to indicate the direction for successive read operations. Value Meaning <br>EVENTLOG_FORWARDS_READ The log is read in chronological order. <br>This flag cannot be used with EVENTLOG_BACKWARDS_READ.<br>&nbsp;<br>EVENTLOG_BACKWARDS_READ The log is read in reverse chronological order. <br>This flag cannot be used with EVENTLOG_FORWARDS_READ.<br>dwRecordOffset <br>[in] Specifies the log-entry record number at which the read operation should start. This parameter is ignored unless dwReadFlags includes the EVENTLOG_SEEK_READ flag. <br><br>lpBuffer <br>[out] Pointer to a buffer for the data read from the event log. This parameter cannot be NULL, even if the nNumberOfBytesToRead parameter is zero. <br>The buffer will be filled with an EVENTLOGRECORD structure. <br><br>nNumberOfBytesToRead <br>[in] Specifies the size, in bytes, of the buffer. This function will read as many whole log entries as will fit in the buffer; the function will not return partial entries, even if there is room in the buffer. <br><br>pnBytesRead <br>[out] Pointer to a variable that receives the number of bytes read by the function. <br><br>pnMinNumberOfBytesNeeded <br>[out] Pointer to a variable that receives the number of bytes required for the next log entry. This count is valid only if ReadEventLog returns zero and GetLastError returns ERROR_INSUFFICIENT_BUFFER. <br><br>Return Values<br>If the function succeeds, the return value is nonzero.<br>If the function fails, the return value is zero. To get extended error information, call GetLastError. <br><br>Remarks<br>When this function returns successfully, the read position in the error log is adjusted by the number of records read. Only a whole number of event log records will be returned. <br>Note &nbsp;The configured filename for this source may also be the configured filename for other sources (several sources can exist as subkeys under a single logfile). Therefore, this function may return events that were logged by more than one source. <br><br>Requirements <br>&nbsp; Windows NT/2000/XP: Included in Windows NT 3.1 and later.<br>&nbsp; Windows 95/98/Me: Unsupported.<br>&nbsp; Header: Declared in Winbase.h; include Windows.h.<br>&nbsp; Library: Use Advapi32.lib.<br>&nbsp; Unicode: Implemented as Unicode and ANSI versions.<br><br>
 
例子:<br>void DisplayEntries( )<br>{<br>&nbsp; &nbsp; HANDLE h;<br>&nbsp; &nbsp; EVENTLOGRECORD *pevlr; <br>&nbsp; &nbsp; BYTE bBuffer[BUFFER_SIZE]; <br>&nbsp; &nbsp; DWORD dwRead, dwNeeded, cRecords, dwThisRecord; <br>&nbsp;<br>&nbsp; &nbsp; // Open the Application event log. <br>&nbsp; &nbsp; h = OpenEventLog( NULL, &nbsp; &nbsp;// use local computer<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Application"); &nbsp; // source name<br>&nbsp; &nbsp; if (h == NULL) <br>&nbsp; &nbsp; &nbsp; &nbsp; ErrorExit("Could not open the Application event log."); <br>&nbsp;<br>&nbsp; &nbsp; pevlr = (EVENTLOGRECORD *) &amp;bBuffer; <br>&nbsp;<br>&nbsp; &nbsp; // Get the record number of the oldest event log record.<br><br>&nbsp; &nbsp; GetOldestEventLogRecord(h, &amp;dwThisRecord);<br><br>&nbsp; &nbsp; // Opening the event log positions the file pointer for this <br>&nbsp; &nbsp; // handle at the beginning of the log. Read the event log records <br>&nbsp; &nbsp; // sequentially until the last record has been read. <br>&nbsp;<br>&nbsp; &nbsp; while (ReadEventLog(h, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// event log handle <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EVENTLOG_FORWARDS_READ | &nbsp;// reads forward <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EVENTLOG_SEQUENTIAL_READ, // sequential read <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// ignored for sequential reads <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pevlr, &nbsp; &nbsp; &nbsp; &nbsp;// pointer to buffer <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BUFFER_SIZE, &nbsp;// size of buffer <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;dwRead, &nbsp; &nbsp; &nbsp;// number of bytes read <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;dwNeeded)) &nbsp; // bytes in next record <br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; while (dwRead &gt; 0) <br>&nbsp; &nbsp; &nbsp; &nbsp; { <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Print the record number, event identifier, type, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // and source name. <br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%02d &nbsp;Event ID: 0x%08X ", <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwThisRecord++, pevlr-&gt;EventID); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("EventType: %d Source: %s/n", <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pevlr-&gt;EventType, (LPSTR) ((LPBYTE) pevlr + <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sizeof(EVENTLOGRECORD))); <br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwRead -= pevlr-&gt;Length; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pevlr = (EVENTLOGRECORD *) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((LPBYTE) pevlr + pevlr-&gt;Length); <br>&nbsp; &nbsp; &nbsp; &nbsp; } <br>&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; pevlr = (EVENTLOGRECORD *) &amp;bBuffer; <br>&nbsp; &nbsp; } <br>&nbsp;<br>&nbsp; &nbsp; CloseEventLog(h); <br>} <br>
 
看不懂C<br><br>有没有Delphi的实例!?
 
对不起,没有pascal的例子,不过api的东西看c还是比较好的。
 
不好意思,由于小弟一直没有时间,故现在才结贴,万分歉意!
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
923
SUNSTONE的Delphi笔记
S
I
回复
0
查看
829
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部