Exemplo n.º 1
0
// static member function (callback)
void BaseService::ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv) {

    // Get a pointer to the C++ object
    BaseService* pService = m_pThis;
    
    // Register the control request handler
    pService->m_hServiceStatus =
		RegisterServiceCtrlHandler(pService->m_szServiceName, Handler);

    if (pService->m_hServiceStatus == NULL)
        return;

	// Start the initialization
	pService->SetStatus(SERVICE_START_PENDING);

	if (pService->OnInitialize()) {
		pService->SetStatus(SERVICE_RUNNING);
        pService->Run();
	}
    // Tell the service manager we are stopped
    pService->SetStatus(SERVICE_STOPPED);

}