Platform SDK: Debugging and Error Handling

RegisterEventSource

The RegisterEventSource function retrieves a registered handle to an event log.

HANDLE RegisterEventSource(
  LPCTSTR lpUNCServerName,  // server name
  LPCTSTR lpSourceName      // source name
);

Parameters

lpUNCServerName
[in] Pointer to a null-terminated string that specifies the Universal Naming Convention (UNC) name of the server on which this operation is to be performed. If this parameter is NULL, the operation is performed on the local computer.
lpSourceName
[in] Pointer to a null-terminated string that specifies the name of the source referenced by the returned handle. The source name must be a subkey of a logfile entry under the EventLog key in the registry. For example, WinApp is a valid source name if the registry has the following key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Event
Log\Application\WinApp\Security\System

Return Values

If the function succeeds, the return value is a handle that can be used with the ReportEvent function.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

If the source name cannot be found, the event logging service uses the Application logfile; it does not create a new source. Events are reported for the source, however, there are no message and category message files specified for looking up descriptions of the event identifiers for the source.

To close the handle to the event log, use the DeregisterEventSource function.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Event Logging Overview, Event Logging Functions, DeregisterEventSource, ReportEvent