File: Windows.hs

package info (click to toggle)
haskell-open-browser 0.2.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 72 kB
  • sloc: haskell: 76; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Web.Browser.Windows
( openBrowserWindows
) where

import System.Win32.Types (INT, HANDLE, HINSTANCE, LPCTSTR,
                           handleToWord, nullPtr, withTString)

openBrowserWindows :: String -> IO Bool
openBrowserWindows url =
    withTString "open" $ \openStr ->
        withTString url $ \urlStr ->
            exitCodeToBool `fmap` c_ShellExecute nullPtr
                                                 openStr
                                                 urlStr
                                                 nullPtr
                                                 nullPtr
                                                 1
  where exitCodeToBool hinst | handleToWord hinst > 32 = True
                             | otherwise               = False

-- https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx
foreign import WINDOWS_CCONV unsafe "windows.h ShellExecuteW"
    c_ShellExecute :: HANDLE  -- _In_opt_
                   -> LPCTSTR -- _In_opt_
                   -> LPCTSTR -- _In_
                   -> LPCTSTR -- _In_opt_
                   -> LPCTSTR -- _In_opt_
                   -> INT     -- _In_
                   -> IO HINSTANCE