Click here to Skip to main content
14,334,763 members

IEventLogger - COM Interface for easy Event Logging

Rate this:
4.38 (5 votes)
Please Sign up or sign in to vote.
4.38 (5 votes)
22 Mar 2004
Easy to use Interface for Event Logging based on CXEventLog class


I needed one simple interface for logging messages on the NT system, so I use the CXEventLog class written by Hans Dietrich to create the IEventLogger interface. Basically I made some minor changes to this class and wrapped it with a simple COM Interface. The only one dummy message will be linked to this object. The COM object can be simple used by all applications without linking any additional modules.

IEventLogger - the interface

The interface should be simple so it contains only three following functions:

HRESULT LogError (BSTR sMessage);
HRESULT LogInfo (BSTR sMessage);
HRESULT LogWarning (BSTR sMessage);

Calling one of those functions for the first time causes internal initialization of the underlying logging class:

  • find out the name of the hosting application
  • find out the name and path of the module hosting the messages (our component)
  • register with those information for NT Event Logging

Create the component EventLogWriter

The COM object EventLogWriter is a simple ATL based COM wrapper for the CXEventLog class. The compiled message resource will be linked with this component. The resulting module EventLogWriter.dll can be copied to any directory. Before using it it must be registered once. (Use regsvr32)

Using the Interface

A small application is supplied to demonstrate the usage of the component, it is a simple dialog based MFC program. The constructor for the application is initializing the COM and the destructor is uninitializing it. The component will be created in the function OnInitDialog() and released in the destructor. The function OnButtonWriteLog() is demonstrating the usage of the interface.

You can create the instance of the interface including the header file and the interface definition file into your project and make instance of it like this:

#include "EventLogWriter.h"    //definition for IEventLogger interface

        * * *

// We get the IEventLogger interface
HRESULT hr = CoCreateInstance(CLSID_EventLogger, NULL,
  CLSCTX_INPROC_SERVER, IID_IEventLogger, (void**)(&m_pEventLogger));
if (FAILED(hr)) {
    MessageBox(_T("The component: EventLogWriter.EventLogger"
      "\ncould not be created! "), _T("Error"));


  • I used the CXEventLog class written by Hans Dietrich.
  • The tutorial of Daniel Lohmann helped me to understand the NT-Logging subject.

To learn more details about this subject I recommend their contributions on this site.


  • March 21st, 2004 Initial version


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Germany Germany
No Biography provided

Comments and Discussions

QuestionWinXP Pin
demonic_death2-Oct-08 22:14
memberdemonic_death2-Oct-08 22:14 
AnswerRe: WinXP Pin
_Reinhard19-Feb-09 20:00
member_Reinhard19-Feb-09 20:00 
QuestionWho wrote this? Pin
Jörgen Sigvardsson23-Mar-04 5:51
memberJörgen Sigvardsson23-Mar-04 5:51 
AnswerRe: Who wrote this? Pin
Steve Mayfield23-Mar-04 7:33
memberSteve Mayfield23-Mar-04 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 22 Mar 2004


14 bookmarked