Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Wilfried Mestdagh
Hello Paul,

 Isn't there anyway to get the threadid of the service application ?

   Service.ServiceThread.ThreadID;

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Paul


 The standard Borland service unit runs a perfectly normal application
 message pump, and you can drop event drive components like ICS, timers,
 etc, onto the form and they just work, and you can post message to the
 form handle.

How to post the message to what handle.
If you create a new service application, you can drop non-UI components on 
it.
I have tried posting a message (postmessage/ postThreadMessage) to the 
Service handle and servive threadid, but none of them seem to work
Am I missing something here ?

Paul


Main Service application unit :

type
  TRPPollSvc = class(TService)
procedure ServiceExecute(Sender: TService);
procedure ServiceStart(Sender: TService; var Started: boolean);
procedure ServiceStop(Sender: TService; var Stopped: boolean);
procedure ServiceDestroy(Sender: TObject);
procedure ServiceCreate(Sender: TObject);
procedure WMError(var message: TMessage); message WM_ERROR;
  private
{ Private declarations }
PServer: TPSvc;
FLogfileName  : string;
FLogInitiated : boolean;
procedure Display(Msg: string);
  public
function GetServiceController: TServiceController; override;
{ Public declarations }
  end;

var
  RPPollSvc: TRPPollSvc;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  RemotePassPollSvc.Controller(CtrlCode);
end;

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

procedure TRPPollSvc.ServiceExecute(Sender: TService);
begin
  while not terminated do ServiceThread.ProcessRequests(true);
end;

procedure TRPPollSvc.ServiceStart(Sender: TService; var Started: boolean);
begin
  // give handle to server object - it needs it to post a message to the 
service application
  PServer.MainHandle:= ServiceThread.ThreadID;// .Handle;
  if PServer.StartServer then Started:= true
else Started:= false;
end;

procedure TRPPollSvc.ServiceStop(Sender: TService; var Stopped: boolean);
begin
  PServer.StopServer;
  Stopped:= true;
end;

procedure TRPPollSvc.ServiceDestroy(Sender: TObject);
begin
  if Assigned(PServer) then
begin
  PServer.Free;
  PServer:= nil;
end;
end;

procedure TRPPollSvc.ServiceCreate(Sender: TObject);
begin
  PServer:= TPSvc.Create;
  PServer.OnDisplay:= Display;
  FLogFileName:= ChangeFileExt(Application.ExeName, '.log');
end;

procedure TRPPollSvc.Display(Msg: string);
var
  lFile: TextFile;
begin
  AssignFile(lFile, FLogFileName);
  try
try
  if not FileExists(FLogFileName) then ReWrite(lFile)
  else Append(lFile);
  if not FLogInitiated then  //just opened
begin
  FLogInitiated:= true;
  WriteLn(lFile, Msg);
end;
  Writeln(lFile, Msg);
finally
  CloseFile(lFile);
end;
  except
  end;
end;

procedure TRPPollSvc.WMError(var message: TMessage); //message WM_ERROR;
begin
  Display('Error');
end;

end.


From a thread within the server object I've tried to post a message to the 
service handle/threadID
PostThreadMessage(MainHandle, WM_ERROR, 0, 0);


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Angus Robertson - Magenta Systems Ltd
From a thread within the server object I've tried to post a message 
to the service handle/threadID
 procedure TRPPollSvc.WMError(var message: TMessage); //message 
 WM_ERROR;
PostThreadMessage(MainHandle, WM_ERROR, 0, 0);

It should be: 

PostMessage (RPPollSvc.Handle, WM_ERROR, 0, 0);

which is the context in which the application is running and in which 
you are listening for the message.  

But looking at my own code, I don't seem to sending any private messages 
in my one historic service, all my recent (five years) service 
applications have been dual purpose service/interactive.  

Angus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Paul
Hi Angus,

That's was my first impression also, however RPPollSvc.Handle doesn't exist 
:-(


Paul

 It should be:

 PostMessage (RPPollSvc.Handle, WM_ERROR, 0, 0);



-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Wilfried Mestdagh
Hello Paul,

 That's was my first impression also, however RPPollSvc.Handle doesn't exist
 :-(

Correct. TService is derrived from TDataModule and has no windows
handle. However you can make one with AllocateHWND.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Arno Garrels
Wilfried Mestdagh wrote:
 Hello Paul,
 
 That's was my first impression also, however RPPollSvc.Handle doesn't
 exist :-(
 
 Correct. TService is derrived from TDataModule and has no windows
 handle. However you can make one with AllocateHWND.

That's probably the best way. 

If you need to receive custom messages in ServiceThread's pump, why? 
you could do something like this: 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;

type
  TService1 = class(TService)
procedure ServiceExecute(Sender: TService);
  protected
function DoCustomControl(CtrlCode: DWord): Boolean; override;  
  private
{ Private-Deklarationen }
  public
function GetServiceController: TServiceController; override;
{ Public-Deklarationen }
  end;

var
  Service1: TService1;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  Service1.Controller(CtrlCode);
end;

function TService1.DoCustomControl(CtrlCode: DWord): Boolean;
begin
if CtrlCode = 256 then
beep
end;

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

procedure TService1.ServiceExecute(Sender: TService);
begin
while not terminated do
begin
ServiceThread.ProcessRequests(False);
PostThreadMessage(ServiceThread.ThreadID, CM_SERVICE_CONTROL_CODE, 256, 
0);
sleep(500);
end;
end; 

I think CtrlCode 128..255 is reserved.


---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Paul


 Wilfried Mestdagh wrote:
 Hello Paul,

 That's was my first impression also, however RPPollSvc.Handle doesn't
 exist :-(

 Correct. TService is derrived from TDataModule and has no windows
 handle. However you can make one with AllocateHWND.


Thanks Wilfried, got it working with this way :-)


 If you need to receive custom messages in ServiceThread's pump, why?

Have a Http server with 12 threads for various processing and database 
operations.
These threads work completelely independent from the servers operations and 
they get their orders from the server thru a queue (with a CS ).
This works fast (there are no delays, except for the critical section).
I want to inform the server whewnever an error occurs in one of the threads 
without the use of sync objects (delays !).
So posting a message is the fastest way.


Paul





-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Angus Robertson - Magenta Systems Ltd
  That's was my first impression also, however RPPollSvc.Handle 
  doesn't exist
  :-(
 
 Correct. TService is derrived from TDataModule and has no windows
 handle. However you can make one with AllocateHWND.

I guess message problems may have been why I gave up using the Borland 
service environment.  

Except for my latest service using Wilfred's unit (that links both 
environments in the same program), I've been using a simple service 
starter that runs a normal GUI application, and sends it a stop message 
when the service is requested to stop.  This all makes debugging 
trivial.  

Angus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-12 Thread Arno Garrels
Paul wrote:
 Wilfried Mestdagh wrote:
 Hello Paul,
 
 That's was my first impression also, however RPPollSvc.Handle doesn't
 exist :-(
 
 Correct. TService is derrived from TDataModule and has no windows
 handle. However you can make one with AllocateHWND.
 
 
 Thanks Wilfried, got it working with this way :-)
 
 
 If you need to receive custom messages in ServiceThread's pump, why?
 
 Have a Http server with 12 threads for various processing and database
 operations.
 These threads work completelely independent from the servers operations
 and they get their orders from the server thru a queue (with a CS ).
 This works fast (there are no delays, except for the critical section).
 I want to inform the server whewnever an error occurs in one of the
 threads without the use of sync objects (delays !).
 So posting a message is the fastest way.

Yes I also use messages where I can, for logging across thread boarders etc., 
however with using DoCustomControl you don't need another window.
Was just another idea... 

Arno

 
 
 Paul
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Wilfried Mestdagh
Hello Paul,

There is no difference !
PostMessage post a message to a (hidden) window, while PostThreadMessage
post a message to a threadID with a messag pump.

Can you eventually clarify your question ?

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Tuesday, April 11, 2006, 19:43, Paul wrote:

 I want to convert a Http client application into a service application.
 How do I use PostMessage in a service application.
 I've tried with PostMessage /PostThreadMessage with handle= 
 application.Handle, but is doens't seem to work :-(


 Paul 


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Arno Garrels
Paul wrote:
 I want to convert a Http client application into a service application.
 How do I use PostMessage in a service application.
 I've tried with PostMessage /PostThreadMessage with handle=
 application.Handle, but is doens't seem to work :-(

Who shall receive that message? The service application, the service
thread, a worker thread or a window? Or do you want to send a message
to the service from another application?

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
 

 
 Paul
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Paul
Normally, when a Http request is done (thru OnRequestdoen) I post a message 
to the form to restart a next Http request.
This is normally done as PostMessage(handle, MyMessage, 0, 0)
But where can I find the handle of the service application ?
I have a similar problem with a new Httpserver I'm writing.
I have made an object of the complete server, so I can compile it as a 
program or as a service application.
It also has a buch of threads running
This works fine, but now I want one of the threads inform the service thru 
Postmessage so the thread can proceed without the delays of sync objects.

Paul 

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Arno Garrels
Paul wrote:
 Normally, when a Http request is done (thru OnRequestdoen) I post a
 message to the form to restart a next Http request.
 This is normally done as PostMessage(handle, MyMessage, 0, 0)
 But where can I find the handle of the service application ?
 I have a similar problem with a new Httpserver I'm writing.
 I have made an object of the complete server, so I can compile it as a
 program or as a service application.
 It also has a buch of threads running
 This works fine, but now I want one of the threads inform the service thru
 Postmessage so the thread can proceed without the delays of sync objects.

Hm, as far as I recall the delphi service framework implements a service as a 
service thread of type TServiceThread.
TServiceThread has it's own message pump (ProcessRequests) that
processes messages from the SCM only. You probably need a base/main
worker thread?


---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html

 
 Paul
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Wilfried Mestdagh
Hello Paul,

 I have made an object of the complete server, so I can compile it as a
 program or as a service application.

Simple, add a hiden window to the object and post messages to that
windwos hadnle instead of the form.

alternative, you find on my site a simple class to include. then you
make your life simple and have a normal GUI or NT service without any
chnage (same exe).

Angus has just made improvements to the class. I did not have the time
to update on the www, but you can taste it as it is :)

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Tuesday, April 11, 2006, 20:21, Paul wrote:

 Normally, when a Http request is done (thru OnRequestdoen) I post a message
 to the form to restart a next Http request.
 This is normally done as PostMessage(handle, MyMessage, 0, 0)
 But where can I find the handle of the service application ?
 I have a similar problem with a new Httpserver I'm writing.
 I have made an object of the complete server, so I can compile it as a
 program or as a service application.
 It also has a buch of threads running
 This works fine, but now I want one of the threads inform the service thru
 Postmessage so the thread can proceed without the delays of sync objects.

 Paul 


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Paul

 Why not make your object self contained, that is make it as explained 
 above:
 with a thread having a message pump.

But the service application already has a message pump, it wouldn't work 
without it.
The Httpserver already works this way without an additional message pump.
Is there a way I can get this handle ?

Paul

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Paul
Hello Wilfried,

Thanks for your class, but I'm looking for another option.
Interactive services won't be allowed anymore in Vista.

Isn't there anyway to get the threadid of the service application ?


Paul



- Original Message - 
From: Wilfried Mestdagh [EMAIL PROTECTED]
To: ICS support mailing twsocket@elists.org
Sent: Tuesday, April 11, 2006 8:50 PM
Subject: Re: [twsocket] Postmessage in Service application


 Hello Paul,
 
 I have made an object of the complete server, so I can compile it as a
 program or as a service application.
 
 Simple, add a hiden window to the object and post messages to that
 windwos hadnle instead of the form.
 
 alternative, you find on my site a simple class to include. then you
 make your life simple and have a normal GUI or NT service without any
 chnage (same exe).
 
 Angus has just made improvements to the class. I did not have the time
 to update on the www, but you can taste it as it is :)

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Arno Garrels
Paul wrote:
 Hello Wilfried,
 
 Thanks for your class, but I'm looking for another option.
 Interactive services won't be allowed anymore in Vista.

If so it's my end ;( Where can I find infos, please?
Btw: Wilfried's class isn't an interactive service by default.  

 
 Isn't there anyway to get the threadid of the service application ?
 Paul
 
 
 
 - Original Message -
 From: Wilfried Mestdagh [EMAIL PROTECTED]
 To: ICS support mailing twsocket@elists.org
 Sent: Tuesday, April 11, 2006 8:50 PM
 Subject: Re: [twsocket] Postmessage in Service application
 
 
 Hello Paul,
 
 I have made an object of the complete server, so I can compile it as a
 program or as a service application.
 
 Simple, add a hiden window to the object and post messages to that
 windwos hadnle instead of the form.
 
 alternative, you find on my site a simple class to include. then you
 make your life simple and have a normal GUI or NT service without any
 chnage (same exe).
 
 Angus has just made improvements to the class. I did not have the time
 to update on the www, but you can taste it as it is :)
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Paul
Hi Arno,

 If so it's my end ;( Where can I find infos, please?
 Btw: Wilfried's class isn't an interactive service by default.

I've read it a few times on the borland.delphi newsgroups.
For what I remember, Vista will have a much stronger security and for that 
it wont allow any kind of direct interaction with a service.
So communication has to go thru other IPC's like pipes, mailslots. Tcp ...


Paul


Ps, I'm still having problems with the service ThreadId.
You can find it in ServiceThread.Handle (should have known that),
but just assigning a var MainHandle(THandle) to it  without using it, will 
prohibit the service from starting. 

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Postmessage in Service application

2006-04-11 Thread Angus Robertson - Magenta Systems Ltd
  If so it's my end ;( Where can I find infos, please?
  Btw: Wilfried's class isn't an interactive service by default.
 
 I've read it a few times on the borland.delphi newsgroups.
 For what I remember, Vista will have a much stronger security and for 
 that it wont allow any kind of direct interaction with a service.
 So communication has to go thru other IPC's like pipes, mailslots. 
 Tcp ...

There is nothing complicated about messages in most services 
applications.  

The standard Borland service unit runs a perfectly normal application 
message pump, and you can drop event drive components like ICS, timers, 
etc, onto the form and they just work, and you can post message to the 
form handle.  

I've used Wilfried's class for a recent project upgrade to avoid 
maintaining two separate applications.  I did change it slightly since I 
don't want services running interactively, or at least I now have the 
same application running in the service and visible windows 
communicating with wsocket and socket server.  

And I've also tested it in Vista already.  

The main problem with Vista is going to be that even if you are logged 
on as administrator, applications are generally run without 
administrator rights.  This causes lots of problems, for instance you 
can only install a service as an administrator, access the HLM keys ad 
admin, etc.  

There is a right menu option to run a program as an administrator, but 
then you can not pass command arguments.  You can set the properties on 
a short cut to run as administrator, but you don't want to do that for 
install programs.  So installing services is going to be fun under 
Vista.  You can also supposedly set a manifest to run as admin, but it 
does not seem to work, nor do numerous Control Panel applets which lack 
admin rights, but Vista is still an early beta, many things are still 
broken.

Angus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be