comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: NT Service, WinSock
Date: Thu, 26 Oct 2000 16:16:06 GMT
Date: 2000-10-26T16:16:06+00:00	[thread overview]
Message-ID: <8t9lbu$ml1$1@nnrp1.deja.com> (raw)
In-Reply-To: 8t8u9l$4ru$1@zingo.tninet.se

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2784 bytes --]

In article <8t8u9l$4ru$1@zingo.tninet.se>,
  "Peter Hend�n" <phenden@tdab.com> wrote:
> I am doing an overhaul of a Windows NT service. It is
> currently done in C++. I now have a (very tight) time
> window to convince the powers that be to let me rewrite
> this in Ada (I did the original C++ implementation). What
> I would like some help with is how to implement an NT
> service (the service module handler stuff) - sample/boilerplate

Hmmm. There's a nice little discussion of that on the MDSN disk that
should have come with your C++ compiler: "Design a Windows NT Serice..."
in Periodicals 1997. It looks pretty simple. You just need to create a
ServiceMain and Handler routine (with the proper parameter profiles of
course) for each service in your program. If your executable is listed
in the registry as containing a service, the OS calls your main
procedure at startup to perform initialization. As part of that
initialization your main procedure builds a LPSERVICE_TABLE_ENTRY array
containing the name and ServiceMain address for each service in the
executable. You then pass that to StartServiceCtrlDispatcher (You have
to do this within 2 minutes, or the OS will kill your process).

The OS then creates a thread for each ServiceMain (and they all call
their respective ServiceMain's). ServiceMain's should probably implement
a "loop forever" or start a task or something. If you return from
ServiceMain, NT assumes your service stopped, and removes it from the
list of running services.

Similarly, each ServiceMain needs to call RegisterServiceCtrlHandler
with the address of its Handler routine. The Handler routine will get
called (from within the context of the main thread) whenever the OS or
user wants to change the status (eg: start or stop) of your service.

There's also a SetServiceStatus that you need to call to tell Windows
what types of control message you a prepared to handle.

There's actually a large amount of discussion in there about how you
need to communicate between the Handler routine in the main thread and
your ServiceMain's thread. Apparently its enough of a pain that a lot of
folks take the sloppy way out (killing the thread, which can cause
resource leaks if the SCM restarts it before the process exits). I think
there's a place where Ada's task synchronization support really could
help out. However, I'm not sure how your Ada compiler would handle calls
to protected type routines from different threads that weren't created
as Ada tasks.

I know I wrote a lot above. But it really doesn't look too complicated
at all; at least not for someone who has managed to figure out COM, or X
or Windows GUI programming.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.



  reply	other threads:[~2000-10-26 16:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-26  0:00 NT Service, WinSock Peter Hend�n
2000-10-26 16:16 ` Ted Dennison [this message]
2000-10-26 18:52   ` Larry Kilgallen
2000-10-27  1:45     ` Ted Dennison
2000-10-30 15:50       ` Ted Dennison
2000-10-31  1:21         ` Randy Brukardt
2000-10-31  3:27           ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox