有没有办法用C语言写入Windows事件日志?

发布于 2024-11-18 03:58:41 字数 138 浏览 2 评论 0原文

我需要修改一个用 win32 C (不是 c++)编写的简单 Windows 服务。

是否有一个库可以让我在不使用 eventcreate.exe 的情况下将事件日志条目写入 Windows 事件日志?或者我必须修改它才能编译为 C++ 程序吗?

I have a requirement to modify a simple windows service written in win32 C (not c++).

Is there a library I can use to write event log entries to the windows event log without using eventcreate.exe? Or do I have to modify it to be compiled as a c++ program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涫野音 2024-11-25 03:58:41

是的,请参阅函数 ReportEvent及其 示例

扩展名为 .mc 的事件提供程序源文件如下所示:

; // MyEventProvider.mc 
; // This is the header section.
   SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
               Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
               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 the categories of events.
   MessageIdTypedef=WORD
   MessageId=0x1
   SymbolicName=NETWORK_CATEGORY
   Language=English
   Network Events
   ... rest of file omitted

.mc 文件被编译为 .res 文件,该文件链接到 .dll:

要编译消息文本文件,请使用以下命令

 mc -U provider.mc

:要编译 消息文本文件,请使用以下命令:生成消息编译器,请使用以下命令:

rc provider.rc

要创建包含消息表字符串资源的纯资源 DLL,请使用以下命令(您可以从 Visual Studio 命令提示符运行该命令):

   link -dll -noentry provider.res

...

Yes, see the function ReportEvent and its example.

The event provider source file with .mc extension looks like this:

; // MyEventProvider.mc 
; // This is the header section.
   SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
               Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
               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 the categories of events.
   MessageIdTypedef=WORD
   MessageId=0x1
   SymbolicName=NETWORK_CATEGORY
   Language=English
   Network Events
   ... rest of file omitted

The .mc file is compiled into a .res file which is linked into a .dll:

To compile the message text file, use the following command:

 mc -U provider.mc

To compile the resources that the message compiler generated, use the following command:

rc provider.rc

To create the resource-only DLL that contains the message table string resources, use the following command (you can run the command from a Visual Studio Command Prompt):

   link -dll -noentry provider.res

...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文