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
|