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 :
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.