我正在尝试通过使用以下代码在 C++ 中获取系统事件日志, 查询事件信息。但是对于某些情况,我得到的是,无效的事件 ID。事件 ID 的值为1073742727。这是错误的。
我的代码如下所示,
EVENTLOG_FULL_INFORMATION evntLogInfo;
DWORD dwByteRequd,cbSize=0,dwBytesToRead=MAX_RECORD_BUFFER_SIZE,dwBytesRead,dwMinimumBytesNeeded,numRecord;
PBYTE pBuffer,currentData,endRecord;
HANDLE eventHandle=OpenEventLog(NULL,"Application");
if(eventHandle==INVALID_HANDLE_VALUE)
cout<<"\nError "<<GetLastError();
else
{
pBuffer=(PBYTE)malloc(MAX_RECORD_BUFFER_SIZE);
if(pBuffer==NULL)
{
cout<<"\nNot enough memory";
CloseEventLog(eventHandle);
}
else
{
//GetEventLogInformation(eventHandle,EVENTLOG_FULL_INFO,&pBuffer,cbSize,&dwByteRequd);
ReadEventLog(eventHandle,EVENTLOG_SEQUENTIAL_READ|EVENTLOG_FORWARDS_READ,0,pBuffer,dwBytesToRead,&dwBytesRead,&dwMinimumBytesNeeded);
if(GetLastError()==ERROR_INSUFFICIENT_BUFFER )
{
pBuffer=(PBYTE)realloc(pBuffer,dwMinimumBytesNeeded);
if(pBuffer==NULL)
{
cout<<GetLastError();
CloseEventLog(eventHandle);
}
else
{
dwBytesToRead=dwMinimumBytesNeeded;
ReadEventLog(eventHandle,EVENTLOG_SEQUENTIAL_READ|EVENTLOG_FORWARDS_READ,0,pBuffer,dwBytesToRead,&dwBytesRead,&dwMinimumBytesNeeded);
}
}
GetNumberOfEventLogRecords(eventHandle,&numRecord);
cout<<numRecord<<"\n";
endRecord=pBuffer+dwBytesToRead;
while(pBuffer<endRecord)
{
currentData=pBuffer;
PEVENTLOGRECORD TempVar = (PEVENTLOGRECORD)currentData;
cout<<((PEVENTLOGRECORD)currentData)->EventID<<"\t";
cout<<((PEVENTLOGRECORD)currentData)->EventType<<"\t";
cout<<((PEVENTLOGRECORD)currentData)->Length<<"\n";
// DWOR error=GetLastError();
}
}
}
谢谢。