关于调用StartServiceCtrlDispatcher()函数,服务启动失败的有关问题

关于调用StartServiceCtrlDispatcher()函数,服务启动失败的问题
在线急等。。。小弟刚接触windows服务方面的编程,照着网上给的例子写的,但运行时调用调用StartServiceCtrlDispatcher()出错,查了下错误代码说是服务进程无法连接到服务控制器上。,这是怎么回事啊?
下面是我照网上写的例子的主函数代码
int main() 

    SERVICE_TABLE_ENTRY ServiceTable[2];
    ServiceTable[0].lpServiceName = "MemoryStatus";
    ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
    
    ServiceTable[1].lpServiceName = NULL;
    ServiceTable[1].lpServiceProc = NULL;

    // 启动服务的控制分派机线程
    if(StartServiceCtrlDispatcher(ServiceTable))
    {
cout<<"OK"<<endl;
         return 0;
    }; 
    return 1;
}
望各位大虾们请教,小弟万分感谢!!!在线急等。。。

------解决方案--------------------
GetLastError 看是什么错误
------解决方案--------------------
被连接的服务起来了才去调用这个方法?

When the service control manager starts a service process, it waits for the process to call the StartServiceCtrlDispatcher function. The main thread of a service process should make this call as soon as possible after it starts up. If StartServiceCtrlDispatcher succeeds, it connects the calling thread to the service control manager and does not return until all running services in the process have terminated. The service control manager uses this connection to send control and service start requests to the main thread of the service process. The main thread acts as a dispatcher by invoking the appropriate Handler function to handle control requests, or by creating a new thread to execute the appropriate ServiceMain function when a new service is started.