Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Application EVENT logging

Posted on 2002-05-06
7
Medium Priority
?
213 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

972 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