Windows Service and the "RegisterServiceCtrlHandlerEx" function

M

McKool

Hello Group,

I'm writting a Windows Services under C# to get some USB events. Because the ServiceBase class does not supports the SERVICE_CONTROL_DEVICEEVENT handler, I'm using P/Invoke to call the RegisterServiceCtrlHandlerEx funtion, using a callback to manage the needed handler. The invoke looks ok, it works.

The problem is when the services stops. My callback function receives the SERVICE_CONTROL_STOP handler but the function don't return. The Services Control shows an Error like: "The Services "myService" could not be stopped". The Service did not returned an error code.

If i hook my debug code to the service and try to stop the service again after the Error Message. I get the cursor in the Dispose function.

I think that with the calling of the ...Ex function, I have to do something more than to "return 0" when the SERVICE_CONTROL_STOP handler is received, .. Know somebody what should it be?


Thanks in advance.
 
M

McKool

Already found. I have to call the ServiceBase.Stop() when receiving the SERVICE_CONTROL_STOP in the HandlerEx callback funtion. Now is all ok.. nevertheless thanks .

KW.
Hello Group,

I'm writting a Windows Services under C# to get some USB events. Because the ServiceBase class does not supports the SERVICE_CONTROL_DEVICEEVENT handler, I'm using P/Invoke to call the RegisterServiceCtrlHandlerEx funtion, using a callback to manage the needed handler. The invoke looks ok, it works.

The problem is when the services stops. My callback function receives the SERVICE_CONTROL_STOP handler but the function don't return. The Services Control shows an Error like: "The Services "myService" could not be stopped". The Service did not returned an error code.

If i hook my debug code to the service and try to stop the service again after the Error Message. I get the cursor in the Dispose function.

I think that with the calling of the ...Ex function, I have to do something more than to "return 0" when the SERVICE_CONTROL_STOP handler is received, .. Know somebody what should it be?


Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top