<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 22, 2015 at 6:40 AM, Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><p>Am 22.10.2015 09:23 schrieb "silvioprog" <<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>>:<br>
> What is the secret to use this it on Windows?</p>
</span><p>The secret is to not use it. It's only real use is in the textmode IDE and maybe there it should be checked whether it can be replaced. </p></blockquote><div>So is there some alternative for signals? ( SetConsoleCtrlHandler() on Windows, but, what in Linux? )</div><div><br></div><div>I have a console application, and I need to block the `Ctrl+C` command, allowing only the `Ctrl+\` (or Ctrl+Break on Windows). See a small example (*) that works fine on Windows (7 / 10) and Linux (*ubuntu 14.04). The original demo was written in C and is hosted here[1].</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p>AFAIR the signals unit is even completely broken if SEH is enabled (default on x86_64-win64, but to be made default on i386-win32).</p>
<p>Regards,<br>
Sven</p></blockquote></div><div>(*)</div><div><br></div><div>=== begin code ===</div><div><br></div><div><div>program project1;</div><div><br></div><div>{$mode objfpc}{$H+}</div><div><br></div><div>uses</div><div>{$IFDEF UNIX}</div><div> BaseUnix,</div><div>{$ENDIF}</div><div> ctypes, sysutils;</div><div><br></div><div>const</div><div> LIB_NAME = {$IFDEF MSWINDOWS}'msvcrt'{$ELSE}'c'{$ENDIF};</div><div><br></div><div>{$IFDEF MSWINDOWS}</div><div> SIGINT = 2;</div><div> SIGILL = 4;</div><div> SIGFPE = 8;</div><div> SIGSEGV = 11;</div><div> SIGTERM = 15;</div><div> SIGBREAK = 21;</div><div> SIGABRT = 22;</div><div>{$ENDIF}</div><div><br></div><div>type</div><div> signal_func = procedure(sig: cint); cdecl;</div><div><br></div><div> function signal(sig: cint; func: signal_func): signal_func; cdecl; external LIB_NAME Name 'signal';</div><div><br></div><div> procedure sigproc(sig: cint); cdecl;</div><div> begin</div><div> signal(SIGINT, @sigproc);</div><div> WriteLn('you have pressed ctrl-c');</div><div> end;</div><div><br></div><div> procedure quitproc(sig: cint); cdecl;</div><div> begin</div><div> WriteLn('ctrl+break (or ctrl+\ on linux) pressed to quit');</div><div> halt(0);</div><div> end;</div><div><br></div><div>begin</div><div> signal(SIGINT, @sigproc);</div><div>{$IFDEF MSWINDOWS}</div><div> signal(SIGBREAK, @quitproc);</div><div>{$ELSE}</div><div> signal(SIGTERM, @quitproc);</div><div>{$ENDIF}</div><div> WriteLn('ctrl-c disabled use ctrl+break (or ctrl+\ on linux) to quit');</div><div> while True do Sleep(100);</div><div>end.</div></div><div><br></div><div>=== end code ===</div><div><br></div><div>[1] <a href="https://www.cs.cf.ac.uk/Dave/C/node24.html">https://www.cs.cf.ac.uk/Dave/C/node24.html</a></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Silvio Clécio</div></div></div>
</div></div>