Adding Categories for Events

Last reviewed: September 25, 1995
Article ID: Q115947
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
    

SUMMARY

The ReportEvent() API accepts a category ID as one of the arguments. The "Microsoft Win32 Programmer's Reference" states that you can add your own categories for events. This article shows you how to add categories that will be recognized by the Event Viewer; however, the article assumes that you already know how to create a message file and add an event source to the registry. For information about basic event logging, please see the logging sample in the Q_A\SAMPLES\logging directory on the "Win32 SDK" CD.

NOTE: The logging example that comes with Visual C++ 2.0 does not bind the MESSAGES.RC to the MESSAGES.DLL unlike the logging example that accompanies the Win32 SDK or NSDN Level 2. Binding MESSAGES.RC to the MESSAGES.DLL can be accomplished by adding MESSAGES.RC to MESSAGES.MAK.

NOTE: If you notice that there are some entries that have a .DLL name and a driver name while you are attempting to read messages from the event log, this means that the event message source has more than one message file. This means you need to parse the string and load each message file.

MORE INFORMATION

Just like events, category IDs are simply IDs in message file resources. However, in order to use categories, the following two requirements must be met:

  • The category IDs must be sequentially numbered, starting with a message ID of 1.
  • The event source entry in the registry must specify the category message file and the number of categories in the message file.

The first requirement is simply a matter of setting the MessageID entries in the message file for the categories. If all of your categories are listed at the top of the message file, you can assign the ID of 1 to the first message. Each message after that automatically gets the next ID value unless you specify otherwise in the MessageID entry.

The category entries in the registry are made by adding values to your event key. Normally, your event log application key already contains EventMessageFile and TypesSupported entries. You should add the following two entries:

  • CategoryMessageFile
  • CategoryCount

The CategoryMessageFile entry is of type REG_EXPAND_SZ. It should be set to the full path to the message file that contains the categories.

The CategoryCount entry is a REG_DWORD type. You should set this entry to the number of categories in the message file specified in CategoryMessageFile.

REFERENCES

"Microsoft Win32 Programmer's Reference," Microsoft Corporation.


Additional reference words: 3.10 3.50
KBCategory: kbprg
KBSubcategory: BseMisc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 25, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.