Solved

EventLog handling

Posted on 2000-05-08
2
487 Views
Last Modified: 2013-12-03
Hey pals,

I'm trying to send some pretty simple messages to Event log file on NT 4.
Well, I tried just to use insertion strings parameter at ReportEvent
function but my boss got scared with "Description could not be found" messages. So I have no choice but to
create MC file.

Something went wrong with that - I performed all steps as written at MSDN
but no effect.
I understand there could be billions of reasons why it doesn't work, therefore I wonder if anyone could send me a simple example that would include : mc file, cpp file with ReportEvent function
call and step-by-step instructions how could I make dll from mc file.

Thanks in advance
0
Comment
Question by:schild
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
Comment Utility
NOTE:

You have to create your own key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\

In my case (see event.reg below), the source name is EventSourceName("Event test").

EventMessageFile must point to your dll or exe file that contains the messages.

You may double-click on event.reg to write values into the registry, but you should modify the path to your program before.


;//------------------------------
;// EVENT.MC
;//------------------------------

MessageId=1000 SymbolicName=EVENT_HELLO
Language=English
Hello from the %1.
..

MessageId= SymbolicName=EVENT_BYE
Language=English
Bye from the %1.
..


//-------------------------------------
// EVENT.CPP
//-------------------------------------

#include <windows.h>
#include <iostream.h>
#include "event.h"

HANDLE  hEventLog=0;
LPCTSTR EventSourceName=TEXT("Event test");

void main(void)
{
   hEventLog=RegisterEventSource(NULL,EventSourceName);
   if(!hEventLog) {
      cout<<"Unable to register"<<endl;
      return;
   }

   LPCTSTR str[]={TEXT("TESTAPP")};
   ReportEvent(hEventLog,EVENTLOG_INFORMATION_TYPE,0,
      EVENT_HELLO,0,1,0,str,0);
   ReportEvent(hEventLog,EVENTLOG_ERROR_TYPE,0,
      EVENT_BYE,0,1,0,str,0);

   DeregisterEventSource(hEventLog);

}

rem ------------------------------------
rem MAKE.BAT
rem ------------------------------------
@echo off
mc event.mc
rc event.rc
cl event.cpp event.res advapi32.lib


-----------------------------------
event.reg
-----------------------------------

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\Event test]
"EventMessageFile"="D:\\TEMP\\EVENT\\EVENT.EXE"
"TypesSupported"=dword:00000007



0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
There must be only the one dot after a message in the .MC file.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

11 Experts available now in Live!

Get 1:1 Help Now