在 C/C++ 中创建 Windows 服务的任何示例?(没有图形用户界面)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8014382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:51:13  来源:igfitidea点击:

Any examples of creating a windows service in C/C++ ? (No GUI)

c++cwindowswinapiwindows-services

提问by T.T.T.

This is a great reference of how it all works at a relatively low level:
http://msdn.microsoft.com/en-us/library/ms685967%28VS.85%29.aspx

这是在相对较低的级别上如何工作的一个很好的参考:http:
//msdn.microsoft.com/en-us/library/ms685967%28VS.85%29.aspx

However, is there a working C/C++ example that shows how to install and run code as a service - all done in code, not using any of the windows gui?

但是,是否有一个可用的 C/C++ 示例来展示如何将代码作为服务安装和运行——所有这些都是在代码中完成的,而不是使用任何 Windows gui?

回答by themel

You might want to have a look at the source. of the Apache Commons Daemon procrunutility. It is a little daunting because of all the things it handles, but then usually the lesson is that you just want to use it instead of reimplementing it anyway :)

您可能想查看源代码。Apache Commons Daemon procrun实用程序。由于它处理的所有事情,这有点令人生畏,但通常教训是你只想使用它而不是重新实现它:)

回答by David Heffernan

I would recommend starting from the Visual Studio service template project.

我建议从 Visual Studio服务模板项目开始