Console Application - Read logged events via DCOM

The following example shows how to view a list of logged messages in C++.

  1. Create a standard Console Application.
  2. Add this Sourcecode:
if( SUCCEEDED(CoInitialize( 0 )) )
{
    ITcEventLogPtr    spEventLogger;
    ITcEnumEventsPtr   spEnumEvts;
   ITcEventPtr       spEvent;
    IDispatchPtr      spDisp;

    if( SUCCEEDED( spEventLogger.CreateInstance(CLSID_TcEventLog))
    {
    spEnumEvts =spEventLogger->EnumLoggedEvents();
    if(spEnumEvts)
    {
        while(spEnumEvts->Next(1, &spDisp) == 1 )
        {
           spEvent = spDisp;
           spEvent->GetMsgString(1033);
           printf( "Event %i; Source %i\n Message = %s\n",spEvent->GetId(), spEvent->GetSrcId(),(char*)spEvent->GetMsgString(1033) );
           spDisp = NULL;
        }
    }
}

spEnumEvts = NULL;
spEvent = NULL;
spEventLogger = NULL;

CoUninitialize();
}

return 0;

The Program uses the ITcEnumEvents Interface to enumerate logged messages.
The text of all logged messages is shown in the Console.

 

Language / IDE

Source code

Visual Studio 6 C++

Sample02.zip