[Ace-users] How to integrate Service_Config frame with NT_Service frame?

zhengfish zhengfish at gmail.com
Fri Jan 25 00:29:10 CST 2008


I'm sorry, I found it's a stupid question.
NT_Service only need to start in the main console program.

I got the answer as following.

==============================slice==================================
	if (opt_debug)
	{

		SetConsoleCtrlHandler (&ConsoleHandler, 1);
		SERVICE::instance ()->svc ();
	}
	else
	{
		ofstream *output_file = new ofstream("nt_svc.log", ios::out);

		if (output_file && output_file->rdstate() == ios::goodbit)
			ACE_LOG_MSG->msg_ostream(output_file, 1);

		ACE_LOG_MSG->open(argv[0],
			ACE_Log_Msg::STDERR
			| ACE_Log_Msg::OSTREAM,
			0);

		ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t): Starting service.\n")));

#if 1
		// Load dynamic service in svc.conf
		int rc = ACE_Service_Config::open( "nt_svc" );
		if ( rc != 0 )
		{
			ACE_ERROR_RETURN( ( LM_ERROR,
				ACE_TEXT( "(%N|%l).%p\n" ), ACE_TEXT( "open" ) ), -1 );
		}
		else
		{
			ACE_DEBUG( ( LM_INFO, "ACE_Service_Config::open( ) is OK\n" ) );
		}
#endif

		ACE_NT_SERVICE_RUN (Beeper,	SERVICE::instance (), ret );

		if (ret == 0)
		{
			ACE_ERROR ((LM_ERROR,
				ACE_TEXT ("%p\n"),
				ACE_TEXT ("Couldn't start service")));
		}
		else
		{
			ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T (%t): Service stopped.\n")));
		}
	}


More information about the Ace-users mailing list