From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=BAYES_00,MSGID_RANDY, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,f3b1b08549f270c0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-10-26 09:30:05 PST Path: supernews.google.com!sn-xit-02!sn-xit-01!supernews.com!novia!newsfeed.skycache.com!Cidera!cpk-news-hub1.bbnplanet.com!news.gtei.net!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: Ted Dennison Newsgroups: comp.lang.ada Subject: Re: NT Service, WinSock Date: Thu, 26 Oct 2000 16:16:06 GMT Organization: Deja.com - Before you buy. Message-ID: <8t9lbu$ml1$1@nnrp1.deja.com> References: <8t8u9l$4ru$1@zingo.tninet.se> NNTP-Posting-Host: 204.48.27.130 X-Article-Creation-Date: Thu Oct 26 16:16:06 2000 GMT X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) X-Http-Proxy: 1.0 x57.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 X-MyDeja-Info: XMYDJUIDtedennison Xref: supernews.google.com comp.lang.ada:1576 Date: 2000-10-26T16:16:06+00:00 List-Id: In article <8t8u9l$4ru$1@zingo.tninet.se>, "Peter Hend�n" 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.