Platform SDK: Exchange Server |
The easiest way to begin debugging a service of Windows NT Server is to artificially run it as a console application — in other words, at a command prompt . This method allows you to step through your code from the first instruction, provides more complete access to the Visual C++ debugger, and supplies a window for viewing MAPI messages.
To set up your service as a console application, you need to handle the return codes from the service control manager and then take the appropriate code path in your startup code.
In other words, when an application runs as a service of Windows NT Server, the service control manager is usually called to find the application's main function. If the process is artificially running as a console application, calls to the service control manager fail. This is when you should branch, and call your main function explicitly.
To run your application as a console application, you must include the WINWRAP.LIB library in your makefile. This will handle the service control manager calls. If you do not include this library, look at the library's source code and make the necessary changes to your application's main function.
For sample code that illustrates this mechanism, see the sample gateway application GWSAMPLE.C. To run the sample gateway as a console application under the Visual C++ debugger, include the notserv startup parameter in your process. To run your executable, choose Settings from the Project menu, and then choose Debug.
Note The notserv argument must always be the first argument specified.