Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendMessage and Windows Services

591 views
Skip to first unread message

Vincent

unread,
Aug 29, 2007, 8:40:47 AM8/29/07
to
Hello,

Is it possible to send a windows message with sendmessage function to a
windows service. Because I have a windows service and an other program
which is the interface of my service and I try to make them communicate
with windows messages but I can't get it to work. I use DefaultHandler
events in my service to get the windows message I send via my interface
but the service seems to doesn't receive anything.
It is possible to do what I try or not ? Some one have code example ?
Is there another simple or better way to achieve what I try ?

regards,
and really thanks for your help.

Vincent

Peter Below (TeamB)

unread,
Aug 29, 2007, 9:45:56 AM8/29/07
to
Vincent wrote:

> Is it possible to send a windows message with sendmessage function to
> a windows service.

Usually not. The service runs in a different desktop than the logged-on
user, and you cannot send windows messages between desktops. Use a
different communication mechanism, like TCP/IP or pipes.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Message has been deleted

Vincent

unread,
Aug 29, 2007, 10:43:03 AM8/29/07
to
>What do you want to do? Is
> the service of yourself?

This is my own service.
The goal of my service is to make some backup at some time or when user
tell it through the interface.
The goal of the interface is to define what to backup and at what time
with some special option. Interface should also get progress information
of the backup from the service to inform user. User can also run backup
immediatly through interface.
I already test to use tcp/ip but I some problem of loosing connection
between service and interface and communication should be done in the
two direction service -> interface and interface -> service. It
complicate to much the application. May be I don't find the good
solution to do this ? Someone have some example?

regards and I really appreciate your help.

Vincent

albert

unread,
Aug 29, 2007, 10:52:55 AM8/29/07
to
I don't see the problem of loosing connection, but it depends on the
components you use. I use the components of Francois Piette
(www.overbyte.be) and they have loads of samples within the package on how
to do this. You cannot use a two-way connection, using tcp ip is always a
'request' and 'answer'. So you'll need some kind of polling mechanism. Your
client is asking the status of the server every x minutes/seconds etc

I would recommend the use of Wilfrid Mestdagh basic service routine. If you
are the administrator and the service is running it will appear in the
systemtray after a minute or so and you can use an ordinary gui to control.
You find the download here:

http://www.mestdagh.biz/soft_hints.html#gui_service

The nice thing is that the configuration interface and the service are all
in the same executable and no difficult protocol needed!

Hope this helps.
ALbert

"Vincent" <vincent.dupuis@X_Xsescoi.fr> schreef in bericht
news:46d5...@newsgroups.borland.com...

Woody (TMW)

unread,
Aug 29, 2007, 11:05:08 AM8/29/07
to
"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d5...@newsgroups.borland.com...

I've already written a database backup program/scheduler for IB and FB. It
has two parts; a service to perform automated tasks and a program to control
the service as well as perform immediate tasks. When the service first
starts, it reads a file of the scheduled tasks. When I change that with the
program, I simply stop and restart the service from the program for changes
to take effect.

HTH
Woody (TMW)


albert

unread,
Aug 29, 2007, 11:05:00 AM8/29/07
to
There are loads of (good working) backup program's already, freeware and
commercial. But that's not the point. It just is fun to write that one
yourself just to learn, just for...

albert
"Woody (TMW)" <wood...@suddenlink.net> schreef in bericht
news:46d589f8$1...@newsgroups.borland.com...

Vincent

unread,
Aug 29, 2007, 11:34:59 AM8/29/07
to
yes there are loads of good backup but mine doesn't backup files but it
backup MySQL databases, so...

regards,

albert a écrit :

Vincent

unread,
Aug 29, 2007, 11:33:20 AM8/29/07
to
I will look at your proposal.

but may be I will look arround pipes communication.

anyway I don't know with communication protocol in my case is the best
and the more simple to implement.

I try to use Indy tcp/ip component but it is not working as expected.

thank you for your time and your help.

albert a écrit :

Remy Lebeau (TeamB)

unread,
Aug 29, 2007, 1:20:57 PM8/29/07
to

"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d5...@newsgroups.borland.com...

> I already test to use tcp/ip but I some problem of


> loosing connection between service and interface

Then you were likely not managing the connection properly to begin with.
TCP works fine in services when used properly. I have made plenty of custom
services for my company that use TCP for their communications and it is a
very stable approach.

> It complicate to much the application.

Then you are not using it correctly. Using TCP should not complicated
either project.


Gambit


Remy Lebeau (TeamB)

unread,
Aug 29, 2007, 1:18:25 PM8/29/07
to

"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d56981$1...@newsgroups.borland.com...

> Is it possible to send a windows message with sendmessage
> function to a windows service.

No. For one thing, services do not have a window to being with. And
second, even if it did, messages cannot cross desktop boundaries. Most
services will not be running in the same desktop that the user is
interacting with.

> I have a windows service and an other program which is the
> interface of my service and I try to make them communicate
> with windows messages but I can't get it to work.

You can't use window messages for that. There are plenty of other IPC
(inter-process communication) techniques that work just fine with services,
such as named pipes, TCP/IP sockets, mailslots, etc.


Gambit


Remy Lebeau (TeamB)

unread,
Aug 29, 2007, 1:25:46 PM8/29/07
to

"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d591f1$1...@newsgroups.borland.com...

> but may be I will look arround pipes communication.

Pipes are a bit harder to use then TCP/IP, and they are not portable to
other platforms. I would suggest sticking with TCP/IP, especially if you
ever plan on accessing the service over a network.

> anyway I don't know with communication protocol in my
> case is the best and the more simple to implement.

That is completely dependant on what you need to send to begin with. You
are likely best off simply designing your own protocol to satisfy your
actual needs. It is not difficult to do that at all.

> I try to use Indy tcp/ip component but it is not working as expected.

Then you are likely not using it correctly.


Gambit


Remy Lebeau (TeamB)

unread,
Aug 29, 2007, 1:23:48 PM8/29/07
to

"albert" <a.d...@rug.nl> wrote in message
news:46d5885d$1...@newsgroups.borland.com...

> You cannot use a two-way connection, using tcp ip is
> always a 'request' and 'answer'.

No, it is not. Where did you get that idea from? TCP/IP is bidirectional.
Data can be traveling in both directions at the same time. The higher-level
protocol that you implement on top of TCP/IP (such as HTTP, SMTP, etc) may
have a request/response design, but TCP/IP itself does not. There is
nothing whatsoever preventing an application from implementing a custom
protocol that can exchange data in both directions at the same time.


Gambit


Remy Lebeau (TeamB)

unread,
Aug 29, 2007, 1:28:15 PM8/29/07
to

"Woody (TMW)" <wood...@suddenlink.net> wrote in message
news:46d589f8$1...@newsgroups.borland.com...

> When I change that with the program, I simply stop
> and restart the service from the program for changes
> to take effect.

There is an easier way. Assuming your service is based on TService, you
could override its virtual DoCustomControl() method. Your control app could
then use the Win32 API ControlService() function to send a custom command to
the service. When received, the service could then reload the file
immediately without having to be restarted at all.


Gambit


Woody (TMW)

unread,
Aug 29, 2007, 1:47:26 PM8/29/07
to
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:46d5ace2$1...@newsgroups.borland.com...

I'll look into this, Remy, thanks. I didn't get overly complex with the
service so I didn't really delve into too much detail about controlling it.
I'll start reading up on it and see what happens. :)

Woody (TMW)


Vincent

unread,
Aug 30, 2007, 2:10:26 AM8/30/07
to
hello Remy,

thnak you for all your remarks,
so I will try to use again tcp/ip to do communication between
interface and service.
Do you have some example on how to do it correctly ?

thanks a lot & regards,
Vincent


Remy Lebeau (TeamB) a écrit :

Vincent

unread,
Aug 30, 2007, 2:15:06 AM8/30/07
to
So assuming I can control my service overriding DoCustomControl() method
and using Win32 API ControlService with the app, I can communicate in
one way app -> service. So now it is possible to send information from
service to app by using sendmessage because of my app is windowed.

Can I do this ?
communication service -> app = sendmessage()
communication app -> service Win32 API ControlService

regards and thanks again to help me.
Vincent

Remy Lebeau (TeamB) a écrit :

Vincent

unread,
Aug 30, 2007, 3:28:58 AM8/30/07
to
Sorry I realize that it is not possible to sendmessage between destop as
someone tell.
so communication service -> app = sendmessage() is impossible.

so I would try tcp/ip again.

Vincent a écrit :

Remy Lebeau (TeamB)

unread,
Aug 30, 2007, 4:29:31 AM8/30/07
to

"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d6...@newsgroups.borland.com...

> So assuming I can control my service overriding DoCustomControl()
> method and using Win32 API ControlService with the app, I
> can communicate in one way app -> service.

That is correct. ControlService() is not meant for general purpose
communication. It is a way for an app to send simple commands for the
service to react to. Nothing more. If you need feedback on the result of
the command, or a 2-way conversation between the app and the service, then
you have to use IPC techniques, as described to you earlier.

> So now it is possible to send information from service to app
> by using sendmessage because of my app is windowed.

As was explained to you earlier, window messages cannot be sent across
desktop boundaries.

> Can I do this ?

Not safely, no. You are better of using pipes or sockets for that instead.

> communication service -> app = sendmessage()
> communication app -> service Win32 API ControlService

I would not recommend that design. You will find that it complicates your
system, requiring both sides to manage two different types of
communications. Don't abuse ControlService() like that. Use a single
medium for both directions of communication. It will makes things much
easier on both sides.


Gambit


Remy Lebeau (TeamB)

unread,
Aug 30, 2007, 4:31:40 AM8/30/07
to

"Vincent" <vincent.dupuis@X_Xsescoi.fr> wrote in message
news:46d6...@newsgroups.borland.com...

> so I will try to use again tcp/ip to do communication
> between interface and service.

That is a good idea.

> Do you have some example on how to do it correctly ?

No, because you did not show what did not work for you before, and did not
explain what was going wrong with it. I'm not going to make assumptions
about type of setup you used for it. If you want further help with it, then
ok. But you have to provide more details about what you are actually using
for it.


Gambit


Vincent

unread,
Aug 30, 2007, 8:49:03 AM8/30/07
to
OK I will take all tcp/ip implementation at the begining.
I will use Indy 10 components (IdCmdTCPServer and TIdTCPClient).
I will try and if I cannot get it to work, I will ask you.

thank you.
Vincent

0 new messages