Solved

Application EVENT logging

Posted on 2002-05-06
7
207 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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