Solved

Application EVENT logging

Posted on 2002-05-06
7
204 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 30

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
List out all word 7 224
bigDiff challenge 17 75
modThree challenge 4 64
Problem to event 3 50
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now