Solved

Application EVENT logging

Posted on 2002-05-06
7
209 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 84
Pressing cancel button with C# UI Automation 3 92
Named range not carried over 10 66
Problem to event 3 114
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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