将 C++ 程序转换为 Windows 服务?

Convert a C++ program to a Windows service?(将 C++ 程序转换为 Windows 服务?)
本文介绍了将 C++ 程序转换为 Windows 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我写了一个控制台程序来做事"——主要是使用boost.如何将其转换为 Windows 服务?我应该事先了解有关 Windows 服务的哪些信息?

I've written a console program that "does stuff" - mainly using boost. How do I convert it to a Windows Service? What should I know about Windows Services beforehand?

推荐答案

有一个关于如何在 MSDN 上设置最小服务的好例子.请参阅有关编写主函数、入口点和示例代码的部分.

There's a good example on how to set up a minimal service on MSDN. See the parts about writing the main function, entry point and also the example code.

一旦您构建并运行了 Windows 服务,您就会发现下一个主要问题:调试很痛苦.没有终端(因此没有 stdout/stderr),一旦您尝试运行可执行文件,它就会实际启动服务,然后返回给您.

Once you've got a windows service built and running, you'll discover the next major gotcha: it's a pain to debug. There's no terminal (and hence no stdout/stderr) and as soon as you try to run the executable it actually launches the service then returns to you.

我发现一个非常有用的技巧是向您的应用程序添加一个 -foreground 选项,这样如果您使用该标志运行,它就会绕过服务启动器代码,而是像常规控制台一样运行应用程序,这使得调试变得非常容易.在 VS.Net 中设置调试选项以使用该标志调用.

One trick I've found very useful is to add a -foreground option to your app so that if you run with that flag then it bypasses the service starter code and instead runs like a regular console app, which makes it vastly easier to debug. In VS.Net set up the debugging options to invoke with that flag.

这篇关于将 C++ 程序转换为 Windows 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)