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

Converting an application to a service

2 views
Skip to first unread message

BrianW

unread,
Apr 2, 2003, 11:45:15 AM4/2/03
to
Hi,

I have a standard application which brings up a window (form), with two child
windows (statistics and "about"). I want to do two things: (1) convert this to
an NT service, (2) have a system tray icon which when clicked on brings up the
main window. Basically the application takes incoming connections from an IIS
dll, contacts a remote server, and returns the reply to the dll. The main window
is mainly used to display the progress of the connection.

I have created a project with a TService component and added the required forms,
but (1)I'm not clear how to get the service to run in this context (how do I get
it to initialise correctly and use the forms?), (2) I have located a TTrayIcon
component, but as it's a sample it's undocumented and I have no real idea how to
use it.

Can anybody point me in the direction of some assistance on converting this to a
service please? Also does anybody know of a _documented_ system tray icon
component which works with BCB6?

Many thanks in advance.

Brian


Randel Bjorkquist

unread,
Apr 2, 2003, 11:57:42 AM4/2/03
to
Hey Brian,

I honestly can not help you with converting an app to a service. I will
actually need to do that towards the end of the current project I'm working
on. But I was just looking at this the other day.

This article's question is "Create forms that minimize or close to the
system tray.

http://www.bcbdev.com/faqs/faq73.htm

Hope this starts you off in the right direction. So best wishes and good
luck,

Randel Bjorkquist


"BrianW" <br...@nospam.co.uk> wrote in message
news:3e8b139d$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Apr 2, 2003, 1:15:00 PM4/2/03
to

"BrianW" <br...@nospam.co.uk> wrote in message
news:3e8b139d$1...@newsgroups.borland.com...

> I have a standard application which brings up a window (form),


> with two child windows (statistics and "about"). I want to do
> two things: (1) convert this to an NT service, (2) have a system
> tray icon which when clicked on brings up the main window.

Can't be done directly. An application and a service are very different
beasts, using different frameworks. Even then, a service usually runs on a
completely different desktop than the one the user sees, and as such can't
directly display windows or system tray icons at all on the user's desktop
(without some extra lower-level programming, that is). Unless the service
is marked as Interactive, but then you lose some of the benefits of making a
service to begin with, as the service won't be able to run outside of a user
login anymore, in which case making a service is usually pointless.

So, the best way to design an efficient service is separate the code into
two pieces - non-visual backend code, and visual UI code. Put the backend
code into the service itself and then put the UI code into a separate normal
application. Then use some form of IPC (inter-process communication), such
as ActiveX/COM, named pipes, tcp sockets, etc, to communicate between the
two. Services are meant to be used as background processes whenever
possible. The only native visual window a service is allowed to have
without extra low-level programming is a standard MessageBox, and even then
you have to pass the special MB_SERVICE_NOTIFICATION flag to the
MessageBox() function so it knows a service is calling it and can then take
the extra measures needed to ensure the popup window is displayed on
whatever desktop is currently visible to the user.

> Basically the application takes incoming connections from an
> IIS dll, contacts a remote server, and returns the reply to the dll.

All of that can (and should) be handled in the service behind the scenes
without any visual windows or anything like that. Especially when servers
are concerned, and especially if you want it to be able to run and handle
requests regardless of whether a user is actually logged into the machine
are not. Services work well as servers, as they don't need any UI in order
to handle and process client connections. UIs are good user-defined
configurations and user-visual status, things that dont need to be in a
service directly.

> The main window is mainly used to display the progress
> of the connection.

The separate application can query the service for that information via IPC
as needed, without interrupting the service's actual work.

> I have created a project with a TService component and added
> the required forms, but (1)I'm not clear how to get the service to
> run in this context (how do I get it to initialise correctly and use
> the forms?)

You should strip the forms out of the TService altogether, and put them into
their own application.

> (2) I have located a TTrayIcon component, but as it's a sample
> it's undocumented and I have no real idea how to use it.

Same here - move the tray icon to the separate application as well.

> Can anybody point me in the direction of some assistance on
> converting this to a service please?

See above. With all that said, I should also comment that it is technically
possible for a service to display windows and tray icons and such. But it
is very ugly to code for, requiring many extra API calls and desktop
tracking and such. It's more hassle than useful. Using a separate
application for the visual aspects is easier to code for and maintain.

> Also does anybody know of a _documented_ system tray
> icon component which works with BCB6?

The native TTrayIcon component is known to be buggy. I would suggest you
handle the tray icon directly and manually, as per this article:

Create forms that miminize or close to the system tray
http://www.bcbdev.com/faqs/faq73.htm


Gambit

BrianW

unread,
Apr 3, 2003, 5:31:00 AM4/3/03
to
Many thanks Gambit for all that detail. I'll forget the GUI part for now. There
is a really irritating "feature" in TService though. If you save the
source/project with a long filename, it part converts it back to a regular
application, then it refuses to build as it can't find WinMain. As I had added
all of the Apro components by this stage, I lost the lot and had to start
afresh!

Brian

"Remy Lebeau (TeamB)" <gamb...@yahoo.com> wrote in message
news:3e8b28a3$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Apr 3, 2003, 1:30:03 PM4/3/03
to

"BrianW" <br...@nospam.co.uk> wrote in message
news:3e8c0d6a$1...@newsgroups.borland.com...

> There is a really irritating "feature" in TService though. If you save
> the source/project with a long filename, it part converts it back to
> a regular application, then it refuses to build as it can't find WinMain.

I have never seen that happen, and I have been using TService for a few
years now in many projects. You are sure you aren't simply naming the file
to something that already exists in another project with the search path?


Gambit

BrianW

unread,
Apr 3, 2003, 3:17:07 PM4/3/03
to
"Remy Lebeau (TeamB)" <gamb...@yahoo.com> wrote in message
news:3e8c7da4$2...@newsgroups.borland.com...

I don't think so - but over the years I have seen some extraordinary behaviour
on the part of BCB! However it's now working - after a fashion, so just to say
again many thanks indeed for your help. Is there a Team A?

> Gambit
>
>


0 new messages