Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WINDOWS EVENTLOG

Status
Not open for further replies.

rwmeds

Programmer
Mar 10, 2003
2
US
Looking at writing code in C++ to place messages in the EVENTLOG. Found pieces, but nothing provide sequences. Looking for examples of placing the message.
 
This is a simple deal..First you must be sure what information you want to get written in Event Log...
I used it in past for the apps to log important events...
I mostly do it in COM/SDK/ATL ways...MFC is also same
Ok I am giving you a simple example
1.Open EventLog using API "OpenEventLog".
2.Mostly it is written for Application Log
3.Then as soon as your one task is done,Use "ReportEvent" to write your event in Application log
4.Then close it using "CloseEventLog"..
In SDK whole series of functions for event log is given..
Hope it helps..
cheers
 
There is a good example in MSDN under the title "Creating a Simple Win32 Service in C++" that uses Event Logging. Perhaps the most time consuming thing for me was getting the process straight to create a MESSAGETABLE entry for the resources and integrating it into my system. While I'm not certain if my way is the "correct" (or even recommended) method, I have found that it works.

My approach was to allow integration of a MESSAGETABLE into my resource file while allowing me to inherit the CNTService class into my own specific service. This required that I combine the CNTService .mc file with the one used by my new service into a single file prior to submitting it to the message compiler as part of a custom build step in the IDE. I then add the resultant files to the resource file via the "View/Resource Includes" menu in the C++ IDE. If you need more detail, let me know, but I would recommend looking at the MSDN examples first and study the way in which the resource file(s) are integrated into your project.

If someone knows a better way, I'm all ears. This method is a little cumbersome.
 
Its better to keep the message file seperate from the code.

In general I tend to use a DLL.

Can't rember quite the steps, but I'll look it up and post back Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top