Example #1
0
static VOID WINAPI ServiceCtrlHandler(const DWORD dwCtrl)
{
   // Handle the requested control code.

	switch(dwCtrl)
	{
		case SERVICE_CONTROL_STOP:
		case SERVICE_CONTROL_SHUTDOWN:

			ServiceShutdown = TRUE;
			ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);

			// Remove PID file and free ressources
			cleanup();
#			ifdef USE_MSRPC
			ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
#			endif // !USE_MSRPC
			return;

		/*case SERVICE_CONTROL_INTERROGATE:
			break;*/

		default:
			break;
	}
}
Example #2
0
DWORD WINAPI service_ctrl(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
{
	switch (dwControl){
		case SERVICE_CONTROL_STOP:
		case SERVICE_CONTROL_SHUTDOWN:
			ReportServiceStatus(SERVICE_STOP_PENDING, 0, 0, 10000);
			g_pMain->StopMain();
			return NO_ERROR;
		case SERVICE_CONTROL_POWEREVENT:
			if( dwEventType == PBT_APMQUERYSUSPEND ){
				//Vista以降は呼ばれない
				OutputDebugString(_T("PBT_APMQUERYSUSPEND\r\n"));
				if( g_pMain->IsSuspendOK() == false ){
					OutputDebugString(_T("BROADCAST_QUERY_DENY\r\n"));
					return BROADCAST_QUERY_DENY;
				}
			}else if( dwEventType == PBT_APMRESUMESUSPEND ){
				OutputDebugString(_T("PBT_APMRESUMESUSPEND\r\n"));
			}
			return NO_ERROR;
		default:
			break;
	}
	return ERROR_CALL_NOT_IMPLEMENTED;
}
Example #3
0
    int CMainApp::Run(int argc, char** argv)
    {
        ReportServiceStatus(SERVICE_START_PENDING);

        if (this->OnRun())
        {
            ReportServiceStatus(SERVICE_RUNNING);

            while(!m_StopEvent.Wait(1))
            {
            }
        }

        ReportServiceStatus(SERVICE_STOP_PENDING);

        this->OnStop();

        ReportServiceStatus(SERVICE_STOPPED);

        return 0;
    }
Example #4
0
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl)
{
	// Handle the requested control code.

	switch (dwCtrl)
	{
	case SERVICE_CONTROL_STOP:
	case SERVICE_CONTROL_SHUTDOWN:

		ServiceShutdown = TRUE;
		ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);

		// Remove PID file and free ressources
		cleanup();
#			if __CYGWIN__ || defined(USE_MSRPC)
		ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
#			endif // __CYGWIN__

	default:
		break;
	}
}
Example #5
0
void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv)
{
	g_hStatusHandle = RegisterServiceCtrlHandlerEx(SERVICE_NAME, service_ctrl, NULL);
	if( g_hStatusHandle != NULL ){
		ReportServiceStatus(SERVICE_START_PENDING, 0, 1, 10000);

		//メインスレッドに対するCOMの初期化
		CoInitialize(NULL);
		//ここでは単純な(時間のかからない)初期化のみ行う
		g_pMain = new CEpgTimerSrvMain;

		ReportServiceStatus(SERVICE_RUNNING, SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_POWEREVENT, 0, 0);

		if( g_pMain->Main(true) == false ){
			OutputDebugString(_T("service_main(): Failed to start\r\n"));
		}
		delete g_pMain;
		g_pMain = NULL;
		CoUninitialize();

		ReportServiceStatus(SERVICE_STOPPED, 0, 0, 0);
	}
}
Example #6
0
VOID WINAPI ServiceHandler( DWORD fdwControl )
{
	UINT uMsg = 0;
	WPARAM wParam = 0;
	LPARAM lParam = 0;
	int iBufferIndex = 0;
	int rc = 0;
	switch( fdwControl )
	{
		case SERVICE_CONTROL_STOP:
		case SERVICE_CONTROL_SHUTDOWN:
			ReportServiceStatus( SERVICE_STOP_PENDING, 1000, 30000 );
			SetEvent(hEventExit);
		break;
	}
}
Example #7
0
VOID WINAPI ServiceMain( DWORD dwArgc, LPTSTR *lpszArgv )
{
	bService = true;

	hEventExit = CreateEvent (0, FALSE, FALSE, NULL);

	hService = RegisterServiceCtrlHandler( SERVICE_NAME, ServiceHandler );

	ReportServiceStatus( SERVICE_START_PENDING, 1000, 5000 );

	ServicePath();

	SetCurrentDirectory( sCurrentPath );

	main(0, NULL);
}
Example #8
0
static VOID WINAPI ServiceMain(const int argc_unused, CARGV argv_unused)
{
	// Register the handler function for the service

	if (!((gSvcStatusHandle = RegisterServiceCtrlHandler(NT_SERVICE_NAME, ServiceCtrlHandler))))
	{
		return;
	}

	// These SERVICE_STATUS members remain as set here

	gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	gSvcStatus.dwServiceSpecificExitCode = 0;

	// Run the actual program
	ReportServiceStatus(SERVICE_STOPPED, newmain(), 3000);
}
Example #9
0
void WaitForServiceStop(void)
{
	WaitForSingleObject(hEventExit, INFINITE);
	ReportServiceStatus(SERVICE_STOP_PENDING, 1000, 5000);
}