From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A4803BCAF for ; Wed, 29 Jun 2005 18:13:48 +0200 (CEST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.202]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5TGDls4026351 for ; Wed, 29 Jun 2005 18:13:48 +0200 Received: by wproxy.gmail.com with SMTP id i4so773778wra for ; Wed, 29 Jun 2005 09:13:47 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=KfRK7b9XoOAxY7ocl7RU1shCjHjsgFJq7Fp47oNvoQrr1N6q4MibOg6uokCxsiI8xALJLdo1xMx/aMaxupO5n5T7b5LMLIPcl2CR+39DTHkUJaNvUMYaklVjGc9LF/jGD9EXx+xNsolvz0QnJPU34nwrpvTmSie35QekfDD6WDA= Received: by 10.54.8.31 with SMTP id 31mr132637wrh; Wed, 29 Jun 2005 09:13:46 -0700 (PDT) Received: by 10.54.91.4 with HTTP; Wed, 29 Jun 2005 09:13:46 -0700 (PDT) Message-ID: <8008871f0506290913518bba6b@mail.gmail.com> Date: Wed, 29 Jun 2005 12:13:46 -0400 From: "Christopher A. Watford" Reply-To: "Christopher A. Watford" To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Keyboard interrupt in Windows In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Miltered: at nez-perce with ID 42C2C8BB.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 posts:01 winmain:01 toplevel:01 toplevel:01 bool:01 handler:01 handler:01 bool:01 wrote:01 thread:02 ctrl:03 ctrl:03 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: On 6/29/05, Nathaniel J. Gaylinn wrote: >=20 > In Linux, OCaml uses signals to break out of the current evaluation (when > you press Ctrl+C to cut out of an infinite loop). However, Windows doesn'= t > support signals. What does OCaml do differently under Windows to make thi= s > work? >=20 > -- Nate Gaylinn Win32 DOES support signals, it just does not send any signal on CTRL+C. A second thread opens that posts a message to WinMain. The OCaml Windows IDE has an example of using this to send the interrupt to the toplevel. In the following file at the very bottom: http://dorm.tunkeymicket.com/OCamlWinPlus/Release/src/startocaml.c // The following sends a CTRL+C/CTRL+BREAK to the console. GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pi.dwProcessId) Note you MUST write to the Win32 Pipe Handle AFTER you call the break, otherwise your application will have no idea the pipe was interrupted. As far as how the toplevel itself handles the CTRL_BREAK_EVENT: // PHANDLER_ROUTINE looks like: BOOL WINAPI HandlerRoutine(DWORD dwCtrlType= ); // Add - TRUE to add a handler, FALSE to remove the handler BOOL SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add); And the CTRL_*_EVENTs you can handle are: CTRL_C_EVENT CTRL_BREAK_EVENT CTRL_CLOSE_EVENT - [X] clicked CTRL_LOGOFF_EVENT - user logoff CTRL_SHUTDOWN_EVENT - machine shutdown or service shutdown Hope that helps. --=20 Christopher A. Watford christopher.watford@gmail.com http://dorm.tunkeymicket.com