Why Does My Vector<PEVENTLOGRECORD> Mysteriously Get Cleared?

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-12-29T06:35:12Z Indexed on 2010/12/29 6:54 UTC
Read the original article Hit count: 250

Filed under:
|
|

Hello everyone,

I am making a program that reads and stores data from Windows EventLog files (.evt) in C++. I am using the calls OpenBackupEventLog(ServerName, FileName) and ReadEventLog(...). Also using this: PEVENTLOGRECORD

Anyway, without supplying all of the code, here is the basic idea:
1. I get a handle to the .evt file using OpenBackupEventLog() and passing in a file name.
2. I then use ReadEventLog() to fill up a buffer with an unknown number of EventLog messages.
3. I traverse through the buffer and add each message to a vector
4. I keep filling up buffers (repeat steps 2 and 3) until I reach the end of the file.

Here is my code for filling the vector:

vector<PEVENTLOGRECORD> allRecords;
while(_status == ERROR_SUCCESS)
{
   if(!ReadEventLog(...))
       CheckStatus();
   else
       FillVectorFromBuffer(allRecords)
}

// Function FillVectorFromBuffer
FillVectorFromBuffer(vector(PEVENTLOGRECORD) &allRecords)
{
   int bytesExamined = 0;
   PBYTE pRecord = (PBYTE)_lpBuffer;    // This is one of the params in ReadEventLog()
   while(bytesExamined < _pnBytesRead)  // Another param from ReadEventLog
   {
      PEVENTLOGRECORD currentRecord = (PEVENTLOGRECORD)(pRecord);
      allRecords.push_back(currentRecord);
      pRecord += currentRecord->Length;
      bytesExamined += currentRecord->Length;
   }
}

Anyway, whenever I run this, it will get all the EventLogs in the file, and the vector will have everything I want it to. But as soon as this line:

if(!ReadEventLog())

gets called and returns true (aka ReadEventLog() returns false), then every field in my vector gets set to zero.

The vector will still contain the correct number of elements, it's just that all of the fields in the PEVENTLOGRECORD struct are now zero.

Anyone with better debugging experience have any ideas?

Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about eventlog

  • deleting eventlog

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hey, How can I delete a specific eventlog entry (say id 130 with source: Myprog) or delete all eventlogs from a specific source without deleting the whole eventlogs under "Application" folder? public static void deleteEvent() { string logName; if (EventLog.SourceExists(SOURCE)) … >>> More

  • Reading EventLog C# Errors

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have this code in my ASP.NET application written in C# that is trying to read the eventlog, but it returns an error. EventLog aLog = new EventLog(); aLog.Log = "Application"; aLog.MachineName = "."; // Local machine foreach (EventLogEntry entry in aLog.Entries) { if (entry.Source.Equals("tvNZB")) … >>> More

  • get-eventlog issue

    as seen on Server Fault - Search for 'Server Fault'
    I wanted to get a quick report of some log entries I saw on a server, so I ran: Get-Eventlog -logname system -newest 10 -computer fs1 | fl I got events back however the descriptions were all wrong. Here's an example: Index : 1260055 EntryType : Warning InstanceId : 2186936367 Message : The… >>> More

  • Access to Windows 7 log from a remote machine

    as seen on Super User - Search for 'Super User'
    I'm trying to access with EventViewer (from a Windows XP Prof) to a remote machine with Windows 7 (Seven). Before I started the Service "RemoteRegistry" I received an "Access Denied". After started the service I can connet to the machine Log (in EventViewer app) but when i clik on any log as "Application"… >>> More

  • logparser not matching on a LIKE pattern

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hi I seem to have the strangest problem. I am using logparser to search an event log for some text that I know is there (i copied and pasted the string from the event into the sql search string). But the sql LIKE statement is returning a empty results. But other LIKE statments seem to be working file… >>> More