Convert a C++ program to a Windows service?

前端 未结 6 445
感情败类
感情败类 2020-12-01 06:40

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?

6条回答
  •  不思量自难忘°
    2020-12-01 07:26

    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.

    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.

    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.

提交回复
热议问题