简体   繁体   中英

windows service in c++

I want to make an application in c++ which will run periodically. much like an windows service. Is it possible to create a windows service in C++. If yes how?

Any tutorial for this?

EDIT: How can I create an installer for the Windows service?

C++ is compatible enough with C that the traditional approaches work. You build the application as a normal C++ program (starting with main ); in the startup you call StartServiceCtrlDispatcher to inform the OS that your program can run as a service. Windows doesn't care that you use classes internally.

As indicated in another answer, you need to create a normal C++ program (starting with main ), and call StartServiceCtrlDispatcher Win32 API to tell Windows that you want to run this program as a service. Some information on this function can be found in MSDN .

Additionally, you'll need a mechanism to install your service so that it appears in Windows Service Control Panel. And of course, an uninstall feature should also be provided. Typically, all the three functions (ie, install, uninstall and run) are handled in a single executable. The difference in these three is indicated via command line parameters.

You've not indicated what version of VC++ you are using. If you are going with managed .NET code, then it's quite easy as Windows Service template is prebuilt into Visual Studio.

However, if you are going with VC++ 6 (or 100% unmanaged code), then you need to know a lot of low level details. Further choices depend on your know-how of ATL or MFC (if you are going with older versions of the compiler/ runtime).

This might be a good tutorial on creating Windows Services using C++ .

Check out POCO C++ libraries that allow you to write daemons/services with little effort.

http://pocoproject.org/docs/00100-GuidedTour.html

http://pocoproject.org/slides/190-Applications.pdf

maybe I am late, but I write C++ class for windows services creating and want share code you need inherit your class from my base class cWinService http://sprogram.com.ua/en/articles/how-write-service-for-windows-with-cpp

please contact with me if you have any observation. I am not C++ wizard I am just study ;)

Of course it's possible. Not only possible, but that's what the native API is designed for (well, C really, but close enough).

See Jeff Richter's book "Programming Server side Applications for Windows 2000"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM