Solved

Application EVENT logging

Posted on 2002-05-06
7
210 Views
Last Modified: 2013-11-20
I need a simple dialog based application through which I can write an event in windows application log and then any one can view it through event viewer.
0
Comment
Question by:haider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6993682
Hi haider,

take a look at functions OpenEventLog, RegisterEventSource and ReportEvent.

In help about ReportEvent there's a link 'see Event Categories' which leads you
to description of how to create/use message files for the event log.

When you query MSDN for ReportEvent you also will find some sample codes.

hope that helps,

ZOPPO
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 6994027
it is simple class
class CEventLog {
public:
     CEventLog(const char *apAppName);
     ~CEventLog();

     BOOL ReportInformation(DWORD aId, WORD aNumStrings = 0, const char **apMessage = 0);
     BOOL ReportError(DWORD aId, WORD aNumStrings = 0, const char **apMessage = 0);

private:
     HANDLE mHandle;
};

CEventLog::CEventLog(const char *apAppName) {
     mHandle = RegisterEventSource(NULL, apAppName);
}

CEventLog::~CEventLog() {
     if ( mHandle != NULL ) {
          DeregisterEventSource(mHandle);
     }
}

BOOL CEventLog::ReportInformation(DWORD aId, WORD aNumStrings /* = 0 */, const char **apMessage /* = 0 */) {
     if ( mHandle == NULL ) {
          return FALSE;
     }

     if (!ReportEvent(mHandle,     /* event log handle            */
               EVENTLOG_INFORMATION_TYPE,  /* event type                  */
               0,                    /* category zero               */
               aId,                  /* event identifier            */
               NULL,                 /* no user security identifier */
               aNumStrings,          /* one substitution string     */
               0,                    /* no data                     */
               apMessage,            /* address of string array     */
               NULL))                /* address of data             */
          {
               return FALSE;
          }
     
     return TRUE;
}

BOOL CEventLog::ReportError(DWORD aId, WORD aNumStrings /* = 0 */,  const char **apMessage /* = 0 */) {
     if ( mHandle == NULL ) {
          return FALSE;
     }

     if (!ReportEvent(mHandle,     /* event log handle            */
               EVENTLOG_ERROR_TYPE,  /* event type                  */
               0,                    /* category zero               */
               aId,                  /* event identifier            */
               NULL,                 /* no user security identifier */
               aNumStrings,          /* one substitution string     */
               0,                    /* no data                     */
               apMessage,            /* address of string array     */
               NULL))                /* address of data             */
          {
               return FALSE;
          }
     
     return TRUE;
}
0
 

Author Comment

by:haider
ID: 6994650
AlexNek:

I have tried it but I get that event log is unable to find its description from source. How to give that source???
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:AlexNek
ID: 6995201
2 haider
Are you mean this message:
The description for Event ID ( 2 ) in Source ( YourProgram ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event:
"Your Text".
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 100 total points
ID: 6995273
2 haider
One way it is create message Dll, the second create mc file.

Second way. (It is possible that I forget something)
1.Create YourName.mc file

*.mc file sample (after header Trace Messages)
http://www.globalmt.com/MicrosoftFeatures/WMI/MVS/TechnicalDetails.htm

2. Create Custom build
input field : mc $(InputPath) mc -h $(ProjDir) $(InputPath)  
output field: $(ProjDir)\$(InputName).rc $(ProjDir)\$(InputName).h

as result you will have YourName.rc, YourName.h è msgen.bin
3.Add *.rc file to your applicatio Resource View -> Resource includes -> Compile time directives -> #include YourName.rc
0
 

Author Comment

by:haider
ID: 6996509
thanx, its done.
0
 

Author Comment

by:haider
ID: 6996514
Thanx, its done.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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