diff options
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/WinProcess.hs | 17 | ||||
-rw-r--r-- | Utility/winprocess.c | 10 |
2 files changed, 15 insertions, 12 deletions
diff --git a/Utility/WinProcess.hs b/Utility/WinProcess.hs index 36f079d04..31f6cfc69 100644 --- a/Utility/WinProcess.hs +++ b/Utility/WinProcess.hs @@ -11,5 +11,18 @@ module Utility.WinProcess where import Utility.PID -foreign import ccall unsafe "terminatepid" - terminatePID :: PID -> IO () +import System.Win32.Process +import Control.Exception (bracket) +import Control.Monad + +terminatePID :: PID -> IO () +terminatePID p = bracket + (openProcess pROCESS_TERMINATE False p) + (void . c_closeProcess) + (\h -> void $ c_TerminateProcess h 1) + +foreign import ccall unsafe "windows.h TerminateProcess" + c_TerminateProcess :: ProcessHandle -> Int -> IO Int + +foreign import ccall unsafe "windows.h CloseHandle" + c_closeProcess :: ProcessHandle -> IO Bool diff --git a/Utility/winprocess.c b/Utility/winprocess.c deleted file mode 100644 index b6e315573..000000000 --- a/Utility/winprocess.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <windows.h> - -void terminatepid (DWORD pid) { - HANDLE h; - h = OpenProcess(PROCESS_TERMINATE, 0, pid); - if (h != NULL) { - TerminateProcess(h, 1); - } - CloseHandle(h); -} |