Browse thread
OCaml IDE (Camlp4 for code formatting)
-
Nathaniel J. Gaylinn
-
Hendrik Tews
-
Nathaniel J. Gaylinn
-
Hendrik Tews
-
David Brown
-
Nathaniel J. Gaylinn
- Christopher A. Watford
-
Nathaniel J. Gaylinn
-
David Brown
-
Hendrik Tews
-
Nathaniel J. Gaylinn
-
Hendrik Tews
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-06-29 (16:13) |
From: | Christopher A. Watford <christopher.watford@g...> |
Subject: | Re: [Caml-list] Keyboard interrupt in Windows |
On 6/29/05, Nathaniel J. Gaylinn <ngaylinn@cs.brown.edu> wrote: > > 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 this > work? > > -- 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. -- Christopher A. Watford christopher.watford@gmail.com http://dorm.tunkeymicket.com