So Is that mean I can't simply call RegisterServiceCtrlHandlerEx from Delphi?
And does windows 10 fast-startup throws those events too? Because I need to stop my service when Hibernate/Shutdown and resume it on after Waked-up/Startup.
I'm trying this:
function MySvcHandlerFunctionEx(dwControl, dwEventType: DWORD; lpEventData, lpContext: Pointer): DWORD; stdcall;
var _lpContext: PMyDefine;
F: TextFile;
begin
AssignFile(F, 'C:\Test.txt');
try
if FileExists('C:\Test.txt') then
Append(F)
else
Rewrite(F);
WriteLn(F, 'Got Data: ' + inttostr(dwControl));
if dwEventType = WM_POWERBROADCAST then
begin
_lpContext := PMyDefine(lpContext);
WriteLn(F, 'MySvcHandler: ' + IntToStr(dwControl) + ' - ' + _lpContext.s);
end;
finally
Result := NO_ERROR;
CloseFile(F);
end;
end;
procedure TCMCRTEngine.ServiceStart(Sender: TService; var Started: Boolean);
var lpContext: PMyDefine;
begin
...
New(lpContext);
lpContext.s := 'My_Test_Svc';
SvcHandler := RegisterServiceCtrlHandlerEx(PWideChar('MyService'), @MySvcHandlerFunctionEx, lpContext);
end;
And I didn't receive anything yet