Win32 2.5.1.0 → 2.5.2.0
raw patch · 6 files changed
+43/−11 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Win32.Console: commandLineToArgv :: String -> IO [String]
Files
- Graphics/Win32/Menu.hsc +5/−5
- Graphics/Win32/Window.hsc +6/−2
- System/Win32/Console.hsc +25/−2
- System/Win32/Types.hsc +1/−1
- Win32.cabal +1/−1
- changelog.md +5/−0
Graphics/Win32/Menu.hsc view
@@ -79,7 +79,7 @@ checkMenuItem :: HMENU -> MenuItem -> MenuFlag -> IO Bool checkMenuItem menu item check = do- rv <- failIf (== -1) "CheckMenuItem" $ c_CheckMenuItem menu item check+ rv <- failIf (== maxBound) "CheckMenuItem" $ c_CheckMenuItem menu item check return (rv == mF_CHECKED) foreign import WINDOWS_CCONV unsafe "windows.h CheckMenuItem" c_CheckMenuItem :: HMENU -> UINT -> UINT -> IO DWORD@@ -230,13 +230,13 @@ getMenuDefaultItem :: HMENU -> Bool -> GMDIFlag -> IO MenuItem getMenuDefaultItem menu bypos flags =- failIf (== -1) "GetMenuDefaultItem" $ c_GetMenuDefaultItem menu bypos flags+ failIf (== maxBound) "GetMenuDefaultItem" $ c_GetMenuDefaultItem menu bypos flags foreign import WINDOWS_CCONV unsafe "windows.h GetMenuDefaultItem" c_GetMenuDefaultItem :: HMENU -> Bool -> UINT -> IO UINT getMenuState :: HMENU -> MenuItem -> MenuFlag -> IO MenuState getMenuState menu item flags =- failIf (== -1) "GetMenuState" $ c_GetMenuState menu item flags+ failIf (== maxBound) "GetMenuState" $ c_GetMenuState menu item flags foreign import WINDOWS_CCONV unsafe "windows.h GetMenuState" c_GetMenuState :: HMENU -> UINT -> UINT -> IO MenuState @@ -254,7 +254,7 @@ getMenuItemCount :: HMENU -> IO Int getMenuItemCount menu =- failIf (== -1) "GetMenuItemCount" $ c_GetMenuItemCount menu+ failIf (== maxBound) "GetMenuItemCount" $ c_GetMenuItemCount menu foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemCount" c_GetMenuItemCount :: HMENU -> IO Int @@ -262,7 +262,7 @@ getMenuItemID :: HMENU -> MenuItem -> IO MenuID getMenuItemID menu item =- failIf (== -1) "GetMenuItemID" $ c_GetMenuItemID menu item+ failIf (== maxBound) "GetMenuItemID" $ c_GetMenuItemID menu item foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemID" c_GetMenuItemID :: HMENU -> UINT -> IO MenuID
Graphics/Win32/Window.hsc view
@@ -1,4 +1,5 @@ {-# LANGUAGE CApiFFI #-}+{-# LANGUAGE NegativeLiterals #-} #if __GLASGOW_HASKELL__ >= 701 {-# LANGUAGE Trustworthy #-} #endif@@ -20,7 +21,7 @@ import Control.Monad (liftM) import Data.Maybe (fromMaybe)-import Data.Word (Word32)+import Data.Int (Int32) import Foreign.ForeignPtr (withForeignPtr) import Foreign.Marshal.Alloc (allocaBytes) import Foreign.Ptr (FunPtr, Ptr, castFunPtrToPtr, castPtr, nullPtr)@@ -185,7 +186,10 @@ cW_USEDEFAULT :: Pos -- See Note [Overflow checking and fromIntegral] in Graphics/Win32/GDI/HDC.hs-cW_USEDEFAULT = fromIntegral (#{const CW_USEDEFAULT} :: Word32)+-- Weird way to essentially get a value with the top bit set. But GHC 7.8.4 was+-- rejecting all other sane attempts.+cW_USEDEFAULT = let val = negate (#{const CW_USEDEFAULT}) :: Integer+ in fromIntegral (fromIntegral val :: Int32) :: Pos type Pos = Int
System/Win32/Console.hsc view
@@ -25,13 +25,22 @@ setConsoleOutputCP, -- * Ctrl events CtrlEvent, cTRL_C_EVENT, cTRL_BREAK_EVENT, - generateConsoleCtrlEvent + generateConsoleCtrlEvent, + -- * Command line + commandLineToArgv ) where ##include "windows_cconv.h" import System.Win32.Types +import Foreign.C.Types (CInt(..)) +import Foreign.C.String (withCWString, CWString) +import Foreign.Ptr (Ptr) +import Foreign.Storable (peek) +import Foreign.Marshal.Array (peekArray) +import Foreign.Marshal.Alloc (alloca) + foreign import WINDOWS_CCONV unsafe "windows.h GetConsoleCP" getConsoleCP :: IO UINT @@ -59,4 +68,18 @@ foreign import WINDOWS_CCONV safe "windows.h GenerateConsoleCtrlEvent" c_GenerateConsoleCtrlEvent :: CtrlEvent -> DWORD -> IO BOOL --- ToDo: lots more +foreign import WINDOWS_CCONV unsafe "Shellapi.h CommandLineToArgvW" + c_CommandLineToArgvW :: CWString -> Ptr CInt -> IO (Ptr CWString) + +-- | This function can be used to parse commandline arguments and return +-- the split up arguments as elements in a list. +commandLineToArgv :: String -> IO [String] +commandLineToArgv [] = return [] +commandLineToArgv arg = + do withCWString arg $ \c_arg -> do + alloca $ \c_size -> do + res <- c_CommandLineToArgvW c_arg c_size + size <- peek c_size + args <- peekArray (fromIntegral size) res + _ <- localFree res + mapM peekTString args
System/Win32/Types.hsc view
@@ -219,7 +219,7 @@ nullFinalHANDLE = unsafePerformIO (newForeignPtr_ nullPtr) iNVALID_HANDLE_VALUE :: HANDLE-iNVALID_HANDLE_VALUE = castUINTPtrToPtr (-1)+iNVALID_HANDLE_VALUE = castUINTPtrToPtr maxBound foreign import ccall "_open_osfhandle" _open_osfhandle :: CIntPtr -> CInt -> IO CInt
Win32.cabal view
@@ -1,5 +1,5 @@ name: Win32-version: 2.5.1.0+version: 2.5.2.0 license: BSD3 license-file: LICENSE author: Alastair Reid, shelarcy
changelog.md view
@@ -1,5 +1,10 @@ # Changelog for [`Win32` package](http://hackage.haskell.org/package/Win32) +## 2.5.2.0 *March 2017*++* Fix constant underflows with (-1) and unsigned numbers.+* Add `commandLineToArgv`+ ## 2.5.1.0 *Feb 2017* * Add `withHandleToHANDLE` (originally found in the `ansi-terminal` library)