Pues si, si tengo un ejemplo, fue un problema ADIVINAR como rayos hacer para q no se muriera el servicio despues de iniciado pero aqui esta, cuando arranca el sistema.este comienza aemitir un sonido hecho por un Beep y aun asi se inicie o cierre cualquier sesion el sonido permanece, usa TApplicatonService:
Código:
#include "Unit1.h"
#include "stdio.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TService1 *Service1;
//------------------------------------------------------------------------------
TServiceController __fastcall TService1::GetServiceController(void)
{ return (TServiceController) ServiceController;
}
void __stdcall ServiceController(unsigned CtrlCode)
{ Service1->Controller(CtrlCode);
}
//------------------------------------------------------------------------------
__fastcall TService1::TService1(TComponent* Owner) : TService(Owner)
{ //((TApplication *)Application)->OnMessage=CaptureMessage;
}
void __fastcall TService1::ServiceStart(TService *Sender, bool &Started)
{ Accion=0;
Started = true;
}
void __fastcall TService1::ServiceContinue(TService *Sender,bool &Continued)
{ Accion=0;
Continued = true;
}
void __fastcall TService1::ServicePause(TService *Sender, bool &Paused)
{ Accion=1;
Paused = false;
}
void __fastcall TService1::ServiceStop(TService *Sender, bool &Stopped)
{ //Accion=2;
Stopped = false;
}
void __fastcall TService1::ServiceExecute(TService *Sender)
{ try
{ while(Accion!=2)
{ Beep();
Sleep(1000);
ServiceThread->ProcessRequests(false);
}
}
__finally
{ ServiceThread->ProcessRequests(true);
}
}
void __fastcall TService1::ServiceShutdown(TService *Sender)
{ Accion=2;
}
//---------------------------------------------------------------------------
Otra cosa, el codigoq has de ejecutar se encuentra en el evento OnExecute cuando termine este, se termina el hilo del servicio hasta q el usuario u otra rutina lo llama de nuevo, por eso es mejor crear un ciclo q se encargue de todo, como entnderlo....? mira las propiedades y ve la ayuda puesto q verla desde cero no me ayudo mucho q digamos puesto q hay ciertas cosas q NO se cumplen y aun no se xq