Solved

EventLog handling

Posted on 2000-05-08
2
488 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
ID: 2790409
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
ID: 2790417
There must be only the one dot after a message in the .MC file.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

21 Experts available now in Live!

Get 1:1 Help Now