advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Do you think it's worth losing the advantages of developing services using wrappers, such as those provided by ATL and .NET, for the simplicity of writing the code on your own making calls into low-level functions?
Partners & Affiliates
advertisement
advertisement
advertisement
Blue Star Average Rating: 4.6/5 | Rate this item | 71 users have rated this item.
 

Five Steps to Writing Windows Services in C

Windows services are convenient for running background apps and for performing tasks that don't require user interaction. And C (not C++) is the best choice for learning the basics of these console applications. Build and implement a simple service to query the amount of available physical memory and write the result to a text file. Then use what you've learned to write your own Windows services. 


advertisement
hen I had to write my first NT service, I went to MSDN and looked for samples. There, I found "Creating a Simple Win32 Service in C++, an article by Nigel Thompson with an example written in C++. Though the article explained the process quite well, I still felt I was missing important information. I wanted to understand what functions are called, by what framework, and when, but C++ didn't make this easy. The object-oriented approach was convenient, but since calls for low-level Win32 functions are encapsulated by class, it is insufficient for learning about the essence of the Services. This is why I feel C is more suitable for the first steps in writing services or for implementing services that perform simple background tasks. C++ is worth using only after you gain a more thorough understanding of the subject. When I had to leave the place I worked and I had to transfer my knowledge to another person, it was very easy to explain the essence of NT services using my examples written in C.


A service is a console application that runs in the background and performs tasks that don't require user interaction. The Windows NT/2000/XP operating systems offer special support for service programs. The installed services can be configured through the Services applet, available from the Control Panel in Windows NT or from Control Panel | Administrative Tools in Windows 2000/XP. Services can be configured to start automatically when operating system starts, so you dont have to start each of them manually after a system reboot.

This article explains how to create a service that periodically queries the amount of available physical memory and writes the result to a text file. The next sections guide you through the process of building, installing, and implementing the service.

  Next Page: Step 1: The main Function and Global Definitions


Page 1: IntroductionPage 4: Step 3: Handling Control Requests
Page 2: Step 1: The main Function and Global DefinitionsPage 5: Step 5: Testing Your Service
Page 3: Step 2: The ServiceMain Function 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs