Solved

An Urgent Problem With Reading Event Logger

Posted on 1998-05-27
1
465 Views
Last Modified: 2013-12-03
why isn't this program returning the correct EventID code
from the logger and always return 0 even when all events in the logger are with diffrent id  ?
In fact this is very much alike the sample program in the
sdk ?


#include  <stdio.h>
#include "events.hpp"
#include <iostream.h>      

void EventThread::RunThread()
{

      HANDLE h,hEvent;
      EVENTLOGRECORD *m_event;
      BYTE bBuffer[MAX_PATH];
      DWORD dwRead,dwNeeded,cRecords=0,dwThisRecord =0;
      

    h = OpenEventLog(NULL,"Application");
    if (h == NULL)
      {
            cout << "can't open the event logger";
      }

      m_event = (EVENTLOGRECORD*) &bBuffer;

      hEvent = CreateEvent( LPSECURITY_ATTRIBUTES(NULL) ,
                                      FALSE,
                                      FALSE,
                                 "EventHandle");

      if (!GetNumberOfEventLogRecords(h,&cRecords))
            cout << "error . Couldn't read or write ";
      else
            cout << "number of records in the system  event log is :"
                   << cRecords << endl;

      cout << "Waiting for more events \n";
      while(1)
      {
            
            NotifyChangeEventLog(h,hEvent);
            WaitForSingleObject(hEvent,INFINITE);
            {
                  ReadEventLog(h,
                         EVENTLOG_BACKWARDS_READ,
                               0,
                               m_event,
                               sizeof(EVENTLOGRECORD),
                               &dwRead,
                               &dwNeeded);
            

      if (m_event->EventType == EVENTLOG_ERROR_TYPE )
                  {
                        switch (m_event->EventID)
                        {
                        case 4:
                              {
                            cout << " ccc was notified about bad sector on disk ";
                              }
                        default:
                              cout << " A Unknown event was raised ";
                        }
                  }
                        
            m_event = (EVENTLOGRECORD*) &bBuffer;
            }
      }

      CloseEventLog(h);
}


UTL_Status EventThread::StopThread(DWORD number)
{

      // TODO
      return 0;
}



void main()
{

      EventThread* local = new EventThread;
      local->RunThread();

}
0
Comment
Question by:sector
1 Comment
 

Accepted Solution

by:
mwalsh111097 earned 200 total points
ID: 1404369
If you check the return from the ReadEventLog() function, you will find that it is, in fact, failing.  GetLastError returns 0x57, which indicates an invalid parameter to the function.  When you change the flags to be "EVENTLOG_BACKWARDS_READ | EVENTLOG_SEQUENTIAL_READ" and change the buffer size to be "sizeof(bBuffer)" then everything works as it should.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question