Delphi 7 on a 64-bit server 2008, a problem

Has anyone ever tried to connect delphi to its own Windows service process (32-bit application) under 64-bit Windows Server 2008?

When I try to do this, I get the error: Could not create process. Invalid parameter.

If any of you know how to do this, this help will be truly appreciated.

Thank!

+3
source share
2 answers

Delphi, , , . , , . , .

, .

program MyService;

uses
  SysUtils, Classes, Windows, Forms, SvcMgr;

type
  TMyService = class(TService)
  private
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
    procedure ServicePause(Sender: TService; var Paused: Boolean);
    procedure ServiceExecute(Sender: TService);
    procedure ServiceContinue(Sender: TService; var Continued: Boolean);
  protected
    FDescription: string;
    FEventLogSourceName: string;
    procedure Initialise; virtual; abstract;
    class function CreateRunner: TObject; virtual; abstract;
  public
    constructor Create(AOwner: TComponent); override;
    function GetServiceController: TServiceController; override;
  end;
  TMyServiceClass = class of TMyService;

{ TMyService }

constructor TMyService.Create(AOwner: TComponent);
begin
  inherited;
  Initialise;
  OnStart := ServiceStart;
  OnStop := ServiceStop;
  OnPause := ServicePause;
  OnExecute := ServiceExecute;
  OnContinue := ServiceContinue;
end;

procedure TMyService.ServiceStart(Sender: TService; var Started: Boolean);
begin
  Started := True;
end;

procedure TMyService.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
  Stopped := True;
end;

procedure TMyService.ServiceContinue(Sender: TService; var Continued: Boolean);
begin
  ServiceStart(Sender, Continued);
end;

procedure TMyService.ServicePause(Sender: TService; var Paused: Boolean);
begin
  ServiceStop(Sender, Paused);
end;

procedure TMyService.ServiceExecute(Sender: TService);
var
  Runner: TObject;
begin
  Runner := CreateRunner;
  Try
    while not Terminated do begin
      ServiceThread.ProcessRequests(True);
    end;
  Finally
    FreeAndNil(Runner);
  End;
end;

var
  Service: TMyService;

procedure ServiceController(CtrlCode: DWORD); stdcall;
begin
  Service.Controller(CtrlCode);
end;

function TMyService.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure RunAsService(ServiceClass: TMyServiceClass; var Service);
var
  Application: TServiceApplication;
begin
  Application := SvcMgr.Application;
  Application.Initialize;
  Application.CreateForm(ServiceClass, Service);
  Application.Run;
end;

procedure RunAsStandardExecutable(ServiceClass: TMyServiceClass);
var
  Application: TApplication;
  Runner: TObject;
begin
  Application := Forms.Application;
  Application.Initialize;
  Runner := ServiceClass.CreateRunner;
  Try
    while True do begin
      Try
        Application.HandleMessage;
      Except
        Application.HandleException(Application);
      End;
    end;
  Finally
    FreeAndNil(Runner);
  End;
end;

procedure ServiceMain(ServiceClass: TMyServiceClass);
begin
  if FindCmdLineSwitch('RunAsApp', ['-', '/'], True) then begin
    RunAsStandardExecutable(ServiceClass);
  end else begin
    RunAsService(ServiceClass, Service);
  end;
end;

begin
  ServiceMain(TMyService);
end.

, , TMyService, Initialise CreateRunner. CreateRunner - . , , , , .

. - while True. .

+10

IDE ?

Win64, IDE , .

+1

All Articles