Discussion:
TServiceApplication and Forms
(too old to reply)
David Pratt
2008-07-07 15:45:11 UTC
Permalink
I am using CPPBuilder5; am trying to develop a service that allows my
client program to connect to it. Just for testing purposes (for now,
anyway), I want the service to display a form (Dialog) that states whether
the socket is listening or connected. But during my readings, I have come
across a warning to not include forms.hpp in a service application, as
there is a conflicting declaration for the application variable. My question
is:

1.How can I display VCL based forms in a service application?

a. Can I modify the Forms.hpp file (Renaming it or copying it to
the project directory, of course) to exclude the TApplication *Application
variable and just include it instead?
Remy Lebeau (TeamB)
2008-07-07 17:25:31 UTC
Permalink
I want the service to display a form (Dialog) that states whether the
socket is listening or connected.
Don't do that. Services are meant to be background tasks. They should not
have a UI of their own. And in fact, starting in Vista, Microsoft has
completely disabled that feature. The only UI recommended, in any version,
is simple popup messages. The MessageBox() function has a special
MB_SERVICE_NOTIFICATION flag specifically for services to use, or use the
WTSSendMessage() function instead. If you need a more complex UI, then run
a separate non-service app within the user's desktop and have the service
communicate with it via any IPC mechanism of your choosing as needed.
But during my readings, I have come across a warning to not
include forms.hpp in a service application
The Forms unit is already implicitally included by TService's SvcMgr unit.
That is not the issue.
How can I display VCL based forms in a service application?
Don't. It is not safe to do that. Even if the code is technically allowed
by the compiler, the run-time behavior will not be what you expect.


Gambit
Mike Ruskai
2008-07-09 06:04:05 UTC
Permalink
On or about Mon, 7 Jul 2008 10:45:11 -0500 did "David Pratt"
Post by David Pratt
I am using CPPBuilder5; am trying to develop a service that allows my
client program to connect to it. Just for testing purposes (for now,
anyway), I want the service to display a form (Dialog) that states whether
the socket is listening or connected. But during my readings, I have come
across a warning to not include forms.hpp in a service application, as
there is a conflicting declaration for the application variable. My question
1.How can I display VCL based forms in a service application?
a. Can I modify the Forms.hpp file (Renaming it or copying it to
the project directory, of course) to exclude the TApplication *Application
variable and just include it instead?
As Remy said, bad idea. One way to handle what you want is to put as much of
the code as possible outside the TServiceApplication framework, so you can
create a normal VCL project to do your testing, then wrap the code in a
service as the last step.

Alternatively, you can start right with the service, but write a separate
monitor program that uses IPC to get data from the service (named pipes is
probably the easiest option).

Loading...