【发布时间】:2020-11-15 17:10:14
【问题描述】:
我正在尝试根据tutorial 在 C 中创建自己的 Windows 服务。我的事件消息定义文件如下所示
EventLogMessages.mc:
MessageIdTypedef=DWORD
SeverityNames=(
Success=0x0:STATUS_SEVERITY_SUCCESS
Info=0x1:STATUS_SEVERITY_INFO
Warning=0x2:STATUS_SEVERITY_WARNING
Error=0x3:STATUS_SEVERITY_ERROR
)
FacilityNames=(
System=0x0:FACILITY_SYSTEM
Runtime=0x2:FACILITY_RUNTIME
Stubs=0x3:FACILITY_STUBS
Io=0x4:FACILITY_IO_ERROR_CODE
)
LanguageNames=(English=0x409:MSG00409)
; // The following are message definitions.
MessageId=0x1
Severity=Success
Facility=Runtime
SymbolicName=SVCEVENT_STATUS_REPORT
Language=English
Status report: %2.
.
MessageId=0x2
Severity=Error
Facility=System
SymbolicName=SVCEVENT_INIT_SYSCALL_ERROR
Language=English
Essential syscall failed when starting the service: %2.
.
MessageId=0x3
Severity=Error
Facility=Runtime
SymbolicName=SVCEVENT_CUSTOM_ERROR
Language=English
Service-specific error: %2.
.
; // A message file must end with a period on its own line
; // followed by a blank line.
这几乎是来自docs的示例文件的副本。
但是,每当我编译此文件、启动服务并打开事件查看器时,我都会将来自我的服务的所有消息都视为“级别:错误”,即使是那些应该具有较低严重性的消息。
事件 ID 和消息是正确的,但严重性总是错误的。
我打开了生成的头文件EventLogMessages.h,这里好像也没问题。
#define SVCEVENT_STATUS_REPORT ((DWORD)0x00020001L)
高 2 位(表示严重性)正确设置为 0 - STATUS_SEVERITY_SUCCESS。 但无论如何,事件总是显示错误。
有人知道为什么会出错以及如何解决吗?
【问题讨论】:
标签: c windows service event-log