Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Iniciar servicio de windows (https://www.clubdelphi.com/foros/showthread.php?t=60099)

jocey 19-09-2008 19:05:55

Iniciar servicio de windows
 
Hola familia este codigo lo copie de una pagina y cuando lo compilo me da el siguiente error:

Constant expresion violate subrange bounds.

el codigo es el sgte, y el erros es en la linea que tengo subrayada en rojo.

Código Delphi [-]
function iniciarServicio (sMachine, sService: String) : Boolean;
var
  schm,
  schs: SC_Handle;
  ss: TServiceStatus;
  psTemp: PChar;
  dwChkP: DWord;
begin
  ss.dwCurrentState := -1;
  schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
  if (schm>0) then
  begin
    schs := OpenService(schm, PChar(sService), SERVICE_START or
      SERVICE_QUERY_STATUS);
    if (schs>0) then
    begin
      psTemp := nil;
      if (StartService(schs, 0, psTemp)) then
        if (QueryServiceStatus(schs, ss)) then
          while (SERVICE_RUNNING<>ss.dwCurrentState) do
          begin
            dwChkP := ss.dwCheckPoint;
            Sleep(ss.dwWaitHint);
            if (not QueryServiceStatus(schs, ss)) then
              Break;
            if (ss.dwCheckPoint < dwChkP) then
              Break;
          end;
      CloseServiceHandle(schs);
    end;
    CloseServiceHandle(schm);
  end;
  Result := SERVICE_RUNNING=ss.dwCurrentState;
end;

cualquier ayuda sera bienvenida.
Gracias de antemano

DarkMan 19-09-2008 21:29:13

Cita:

Empezado por jocey (Mensaje 315231)
Código Delphi [-]
 
...
  ss.dwCurrentState := -1;
...

SS.dwCurrentState es de tipo cardinal. Según la ayuda de delphi, el tipo cardinal es:

Código Delphi [-]
 
 Type        Range              Format
 Cardinal    0..4294967295      unsigned 32-bit

Si te fijas en el rango que comprende el tipo Cardinal, el -1 no esta incluido. Lo que tu haces en esa línea es asignar -1 a una variable tipo Cardinal, lo que no está permitido.
Espero que esta respuesta te sirva.;)


La franja horaria es GMT +2. Ahora son las 00:58:36.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi