Message Files

Each event sources should register message files that contain description strings for each event identifier, event category, and parameter. Register these files in the EventMessageFile, CategoryMessageFile, and ParameterMessageFile registry values for the event source. You can create one message file that contains descriptions for the event identifiers, categories, and parameters, or create three separate message files. Several applications can share the same message file.

You should typically create message files as dynamic-link libraries (DLL). Use the following procedure to create these DLLs.

    To create a message file
  1. Do not include exported functions in the .C file; include only a stub for the DllMain function. The stub should simply return TRUE.
  2. Use the following command to compile the .C file:
    cl options -fo filename.obj filename.c.
  3. Create an .MC file to define the message resource table. For more information, see Message Compiler Source Files.
  4. Use the message compiler to create .RC and .BIN files from the .MC file. Use the following command: mc filename.mc.
  5. Use the resource compiler to create a .RES file. Use the following command: rc -r -fo filename.res filename.rc.
  6. Use the linker to create a .DLL file. Use the following command line: link -dll -out:filename.dll filename.obj filename.res.

To make it easier for the application to use your message file, create a header file that lists each event. For example, suppose you have defined the following message in your .MC file:

MessageId=0x4
Severity=Error
Facility=System
SymbolicName=MSG_CMD_DELETE
Language=English
File %1 contains %2, which is in error.
 

Your header file should contain the following code:

//
// MessageId: MSG_CMD_DELETE
// MessageText:
//  File %1 contains %2, which is in error.
//
#define MSG_CMD_DELETE                     ((DWORD)0xC0000004L)
 

Now the event-viewing application can use the following procedure to gain access to the description strings in the message file.

    To obtain description strings
  1. Use the RegOpenKey function to open the event source.
  2. Use the RegQueryValueEx function to obtain the EventMessageFile value for the event source, which is the name of the event message DLL.
  3. Use the LoadLibraryEx function to load the event message DLL.
  4. Use the FormatMessage function to obtain the description from the DLL and add the insertion strings.