Daniel Berger
2006-Jun-28 04:10 UTC
[Win32utils-devel] [Fwd: [ruby] win32-service : RegisterServiceCtrlHandlerEx]
Thoughts? -------------- next part -------------- An embedded message was scrubbed... From: "Romuald du Song" <rdusong at gmail.com> Subject: [ruby] win32-service : RegisterServiceCtrlHandlerEx Date: Mon, 26 Jun 2006 00:02:10 +0200 Size: 2587 Url: http://rubyforge.org/pipermail/win32utils-devel/attachments/20060628/8f12e8f1/attachment-0001.mht
Heesob Park
2006-Jun-28 04:54 UTC
[Win32utils-devel] [Fwd: [ruby] win32-service : RegisterServiceCtrlHandlerEx]
Hi, 2006/6/28, Daniel Berger <djberg96 at gmail.com>:> Thoughts? > > > > ---------- ??? ??? ---------- > From: "Romuald du Song" <rdusong at gmail.com> > To: "Daniel Berger" <djberg96 at gmail.com>, stevetuckner > <stevetuckner at usfamily.net>, phasis68 at hotmail.com, sdate at everestkc.net > Date: Mon, 26 Jun 2006 00:02:10 +0200 > Subject: [ruby] win32-service : RegisterServiceCtrlHandlerEx > Hy, > > I am trying to build a ruby service that keep track of log on and log off > on windows machine. > I''ve no windows specific development knowledge so it was hard > for me to find that you could use RegisterServiceCtrlHandlerEx > to register an HandlerEx to be notified of SERVICE_CONTROL_SESSIONCHANGE. > > My problem is that win32-service does not use this function > but RegisterServiceCtrlHandler. > > I''ve no tools and knowledge to extend win32-service to provide this > new functionnality. > > Is this functionnality interesting enough that a win32-service developper > may consider adding it ? > > Thanks you for your time. >I agree to his proposal to extend win32-service for new functionnality. But there is one problem. If you use RegisterServiceCtrlHandlerEx in win32-service, you cannot compile it with VC++ 6.0. Regards, Park Heesob
Patrick Hurley
2006-Jun-28 11:28 UTC
[Win32utils-devel] [Fwd: [ruby] win32-service : RegisterServiceCtrlHandlerEx]
On 6/28/06, Heesob Park <phasis at gmail.com> wrote:> But there is one problem. If you use RegisterServiceCtrlHandlerEx in > win32-service, you cannot compile it with VC++ 6.0.That is not completely true. We could dynamically call it out of advapi32.lib (using LoadLibrary/GetProcAddress). It is a bit of a pain, but completely doable -- sort of like DL for C. pth
Patrick Hurley
2006-Jun-28 13:54 UTC
[Win32utils-devel] [Fwd: [ruby] win32-service : RegisterServiceCtrlHandlerEx]
Since the proof is in the pudding, below is some code to show what I
meant. The down side to this approach is that it requires us to put
some "nasty" constants in our code (stuff that can only be known by
looking in a dev studio header file or some serious reverse
engineering). As there is really no way Microsoft can change these
constants without breaking loads of code it is not a problem, but it
does go against the grain.
If this is a desired approach (it could be a while before we get a
Ruby compiling on a newer tool chain), I would be happy to make a
patch that also softens up the SERVICE_CONTROL_PARAMCHANGE,
SERVICE_CONTROL_NETBINDXXX etc. and HAVE_ENUMSERVICESSTATUSEX. As
these are API (windows version) issues and not really tied to the
compiler we can support them as long as the version of windows does. I
will wait until you complete the revision separating service code from
daemon code, as that is big enough to wreck an easy patch.
pth
#include <stdio.h>
#include <windows.h>
typedef DWORD (WINAPI *LPHANDLER_FUNCTION_EX) (
DWORD dwControl, // requested control code
DWORD dwEventType, // event type
LPVOID lpEventData, // event data
LPVOID lpContext // user-defined context data
);
typedef SERVICE_STATUS_HANDLE (WINAPI *REGISTER_SERVICE_CTRL_HANDLER_EX) (
LPCTSTR lpServiceName, // name of service
LPHANDLER_FUNCTION_EX lpHandlerProc, // handler function
LPVOID lpContext // user data
);
DWORD WINAPI MyCallBack(DWORD dwControl, DWORD dwEventType, LPVOID
lpEventData, LPVOID lpContext)
{
return 0;
}
int main()
{
HMODULE hAdvapi32 = NULL;
REGISTER_SERVICE_CTRL_HANDLER_EX RegisterServiceCtrlHandlerEx = NULL;
if ((hAdvapi32 = LoadLibrary("Advapi32.dll")) == NULL)
{
printf("Unable to load Advapi32.dll\n");
exit(1);
}
if ((RegisterServiceCtrlHandlerEx
(REGISTER_SERVICE_CTRL_HANDLER_EX)GetProcAddress(hAdvapi32,
"RegisterServiceCtrlHandlerExA")) == NULL)
{
printf("Unable to locate RegisterServiceCtrlHandlerEx\n");
exit(2);
}
printf("It''s all good\n");
RegisterServiceCtrlHandlerEx("ServName", MyCallBack, 0);
return 0;
}