Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

EventLog handling

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
schild
Asked:
schild
  • 2
1 Solution
 
NickRepinCommented:
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
 
NickRepinCommented:
There must be only the one dot after a message in the .MC file.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now