First of all, let me explain that this article is not intended to give you information about writing a Windows NT Service.
Normally a Windows NT Service is supposed to be a console win32 application.
But this is not a restriction. In other words, you can write a Windows NT Service that
uses Microsoft Foundation Classes. One way of writing such an application is that
you start from a standard MFC based SDI, MDI or Dialog based application. But soon
you will realize that there is a lot of code that is just useless or is extraneous to the project.
You can obviously just ignore this code, but why have code in your application that you
know is never going to be used? One alternative is to allow AppWizard to generate this extra code
and then go in and manually remove the unnecessary code from your project.
However, what if you want to write another such application? Well you could become expert in
this ‘Code Removing’ process but it certainly wouldn’t be a very effecient use of your time.
A better way would be to have a Custom AppWizard that does this automatically for you. I
felt the need for such an AppWizard when I was writing my second Windows NT Service
that needed to use MFC quite extensively. I created an MFC dialog-based application and then
removed the extra code. Then, I added a new file to the project in which I added all the code
that was necessary to make an application a Windows NT Service. I built the project and
confirmed that it was working fine. After this I created a new project of type “Custom AppWizard”.
This project was based on my previously built project. I chose the “An existing project” option in the
‘Step 1 of 2’ and in ‘Step 2 of 2’ of the Wizard. I also specified the path of my previous project.
After a few minor changes to the template files of the project I succeeded in creating a Custom AppWizard
that could generate a project for a Windows NT Service and that would save me the time of manually removing
unnecessary code every time I wanted to write a service.
The Projects generated by this AppWizard are defined as ‘Minimal Windows NT Services’. If you
create a project from this Custom AppWizard and build it, your application will fulfill all the requirements
of a Windows NT Service, although it will not be doing any thing. In other words, like any other AppWizard,
my template files are used to create the framework for your code so that you only have to be concerned with
code that is specific to your application’s needs.
Installation: Simply copy the NTService.awx file to the “…DevStudioSharedIDETemplate” folder.
Note: If you need help writing and understanding Windows NT Services, please feel free to
Date Last Updated: February 14, 1999