views:

435

answers:

2

As with most "legacy" MSDN pages, the page for ReportEvent has too little information for me to make much sense of it. I've tried searching, but can't find a good, clean, simple example of the function's usage. Could anyone suggest one?

A: 

As I recall it is a pain to set up correctly - you need to add messages to you application using the Message Compiler - if you skip this you won't see useful messages only error codes. Take a look at Creating a Windows NT Service by Using ATL for an example

Stephen Nutt
+1  A: 

I ended up using this:

HANDLE eventLog;
WORD type;
const char* msg;

// ... snip ...

ReportEvent(eventLog, type, 0, 1, NULL, 1, 0, &LPCTSTR(msg), NULL);

Seems to work well enough.

nbolton
The problem with this solution is that it logs jumble (cf: "The description for Event ID 1 from source XYZ.exe cannot be found" on Windows Vista).
Dimitri C.