Recent

Author Topic: UniqueInstanceRaw : send command line parameters  (Read 2001 times)

Mukatai

  • New Member
  • *
  • Posts: 28
UniqueInstanceRaw : send command line parameters
« on: August 27, 2014, 10:29:13 am »
Hi all,

I want use UniqueInstance with a console application. I use the demo of raw version but when i launch a second instance i can't recover the parameters of this in first instance.

i use this code :

Code: [Select]
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, CustApp, uniqueinstanceraw
  { you can add units after this };

type

  { TMyApplication }

  TMyApplication = class(TCustomApplication)
  protected
    procedure DoRun; override;
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
  end;

{ TMyApplication }

procedure TMyApplication.DoRun;
begin
  writeln('Application loop !') ;
  sleep(2000) ;
  // stop program loop
  //Terminate;
end;

constructor TMyApplication.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;

destructor TMyApplication.Destroy;
begin
  inherited Destroy;
end;

var
  Application: TMyApplication;
begin
  if not InstanceRunning('project1',true) then
    begin
      Application:=TMyApplication.Create(nil);
      Application.Title:='My Application';
      Application.Run;
      Application.Free;

    end;
end.

On Windows 7, this code won't work. It block at the SendStringMessage function in UniqueInstanceRaw.pas when i launch a second instance. (the function not return, as an infinite loop)

On Linux, no blocking but I do not get the parameters of the second instance in the first. To find the parameters sent, I track the parameters number of application (Application.ParamCount) and it not change, it's the right methode ?

I search a exemple for UniqueInstanceRaw who send the command line parameters to the already running instance.

Thanks,
Best regards.
« Last Edit: August 29, 2014, 10:37:17 am by Mukatai »

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: UniqueInstanceRaw : send command line parameters
« Reply #1 on: August 30, 2014, 01:02:51 am »
Under windows, SimpleIPC which UniqueInstance uses internally, requires that the program run in a windows message loop, so the ordinary command line program will not work.

Only the component TUniqueInstance which requires LCL can catch the command line parameters

Mukatai

  • New Member
  • *
  • Posts: 28
Re: UniqueInstanceRaw : send command line parameters
« Reply #2 on: September 03, 2014, 02:44:40 pm »
Hi Luiz,

Ok, i will use socket for catch the command line parameters...

Thanks,
Bye.

 

TinyPortal © 2005-2018