Platform SDK: Debugging and Error Handling

Querying the Event Log

If you want to find out how many event records are in the event log, use the GetNumberOfEventLogRecords function. The following example displays the number of event records in the Application event log and the System event log. It opens the logs using the OpenEventLog function and obtains the number of records using GetNumberOfEventLogRecords.

void DisplayEventCount()
{
    HANDLE h;
    DWORD cRecords; 

    // Open the System log. 
 
    h = OpenEventLog(NULL,  // uses local computer 
             "System");     // source name 
    if (h == NULL) 
        ErrorExit("Could not open the System event log."); 
 
    // Get the number of records in the System event log. 
 
    if (!GetNumberOfEventLogRecords(h, &cRecords)) 
        ErrorExit("Could not get the number of records."); 
 
    printf("There are %d records in the System event log.\n", 
        cRecords); 
 
    CloseEventLog(h); 
 
    // Open the Application log. 
 
    h = OpenEventLog(NULL,    // uses local computer  
             "Application");  // source name 
    if (h == NULL) 
        ErrorExit("Could not open the Application event log."); 
 
    // Get the number of records in the Application event log. 
 
    if (!GetNumberOfEventLogRecords(h, &cRecords)) 
        ErrorExit("Could not get number of records."); 
 
    printf("There are %d records in the Application event log.\n", 
        cRecords); 
 
    CloseEventLog(h); 
}