将C ++程序转换为Windows服务? [英] Convert a C++ program to a Windows service?

查看:136
本文介绍了将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上设置最小服务: http://msdn.microsoft.com/en-us/library/ms685967%28VS.85%29.aspx 。请参阅关于编写主函数,入口点和示例代码的部分。

There's a good example on how to set up a minimal service on MSDN: http://msdn.microsoft.com/en-us/library/ms685967%28VS.85%29.aspx . 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.

ve发现非常有用的是为你的应用程序添加一个 -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.

Mand。

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆