示例#1
0
    /**
     * Called when the service is starting.
     *
     * @param dwArgc number of arguments
     * @param lpszArgv pointer to arguments
     */
    public void callback(int dwArgc, Pointer lpszArgv) {
      Advapi32 advapi32;

      advapi32 = Advapi32.INSTANCE;

      serviceControl = new ServiceControl();
      serviceStatusHandle =
          advapi32.RegisterServiceCtrlHandlerEx(serviceName, serviceControl, null);

      reportStatus(Winsvc.SERVICE_START_PENDING, WinError.NO_ERROR, 3000);
      reportStatus(Winsvc.SERVICE_RUNNING, WinError.NO_ERROR, 0);

      onStart();

      try {
        synchronized (waitObject) {
          waitObject.wait();
        }
      } catch (InterruptedException ex) {
      }
      reportStatus(Winsvc.SERVICE_STOPPED, WinError.NO_ERROR, 0);

      // Avoid returning from ServiceMain, which will cause a crash
      // See http://support.microsoft.com/kb/201349, which recommends
      // having init() wait for this thread.
      // Waiting on this thread in init() won't fix the crash, though.
      // System.exit(0);
    }