我首先创建了一个WIN32控制台的工程,然后调用了StartServiceCtrlDispatcher()函数,代码如下:
#include "service.h"
SERVICE_STATUS ssMyServiceStat;
SERVICE_STATUS_HANDLE sshControlHandle;void _CRTAPI1 main(int argc , char ** arg)
{
    SERVICE_TABLE_ENTRY dispath_tbl[] =
    {
        {TEXT("hello service"), (LPSERVICE_MAIN_FUNCTION)service_main},
        {NULL,NULL}
    };
    int iRetCode = 0;//    installService();
        if (!StartServiceCtrlDispatcher(dispath_tbl))
    {
       
       iRetCode = GetLastError();
       _tprintf("error in start dispatcher = %d\n",iRetCode);
//       removeService();    }
    else
    {
       _tprintf("success in start dispatcher\n");
    }}但是StartServiceCtrlDispatcher()返回错误码1063 即ERROR_FAILED_SERVICE_CONTROLLER_CONNECT,在MSDN上的信息如下:
Typically, this error indicates that the program is being run as a console application rather than as a service. 
If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.我不明白为什么这个程序是作为控制台的程序运行的,而又如何让系统认为是一个服务程序呢,请高手赐教,谢谢!