Win32 2.3.1.1 → 2.4.0.0
raw patch · 8 files changed
+158/−43 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- System.Win32.Info: try :: String -> (LPTSTR -> UINT -> IO UINT) -> UINT -> IO String
+ System.Win32.File: fILE_ADD_FILE :: AccessMode
+ System.Win32.File: fILE_ADD_SUBDIRECTORY :: AccessMode
+ System.Win32.File: fILE_ALL_ACCESS :: AccessMode
+ System.Win32.File: fILE_APPEND_DATA :: AccessMode
+ System.Win32.File: fILE_ATTRIBUTE_REPARSE_POINT :: FileAttributeOrFlag
+ System.Win32.File: fILE_CREATE_PIPE_INSTANCE :: AccessMode
+ System.Win32.File: fILE_DELETE_CHILD :: AccessMode
+ System.Win32.File: fILE_EXECUTE :: AccessMode
+ System.Win32.File: fILE_LIST_DIRECTORY :: AccessMode
+ System.Win32.File: fILE_READ_ATTRIBUTES :: AccessMode
+ System.Win32.File: fILE_READ_DATA :: AccessMode
+ System.Win32.File: fILE_READ_EA :: AccessMode
+ System.Win32.File: fILE_TRAVERSE :: AccessMode
+ System.Win32.File: fILE_WRITE_ATTRIBUTES :: AccessMode
+ System.Win32.File: fILE_WRITE_DATA :: AccessMode
+ System.Win32.File: fILE_WRITE_EA :: AccessMode
+ System.Win32.Info: c_GetLongPathName :: LPCTSTR -> LPTSTR -> DWORD -> IO DWORD
+ System.Win32.Info: c_GetShortPathName :: LPCTSTR -> LPTSTR -> DWORD -> IO DWORD
+ System.Win32.Info: c_GetUserName :: LPTSTR -> LPDWORD -> IO Bool
+ System.Win32.Info: getLongPathName :: FilePath -> IO FilePath
+ System.Win32.Info: getShortPathName :: FilePath -> IO FilePath
+ System.Win32.Info: getUserName :: IO String
+ System.Win32.Path: filepathRelativePathTo :: FilePath -> FilePath -> IO FilePath
+ System.Win32.Path: pathRelativePathTo :: FilePath -> FileAttributeOrFlag -> FilePath -> FileAttributeOrFlag -> IO FilePath
+ System.Win32.Process: c_GetCurrentProcessId :: IO ProcessId
+ System.Win32.Process: getCurrentProcessId :: IO ProcessId
+ System.Win32.Types: try :: String -> (LPTSTR -> UINT -> IO UINT) -> UINT -> IO String
+ System.Win32.Types: type LONG_PTR = CIntPtr
+ System.Win32.Types: type ULONG_PTR = CUIntPtr
- System.Win32.Types: type ATOM = UINT
+ System.Win32.Types: type ATOM = WORD
- System.Win32.Types: type LPARAM = LONG
+ System.Win32.Types: type LPARAM = LONG_PTR
- System.Win32.Types: type LRESULT = LONG
+ System.Win32.Types: type LRESULT = LONG_PTR
- System.Win32.Types: type SIZE_T = DWORD
+ System.Win32.Types: type SIZE_T = ULONG_PTR
- System.Win32.Types: type WPARAM = UINT
+ System.Win32.Types: type WPARAM = UINT_PTR
Files
- Graphics/Win32/Window.hsc +1/−0
- System/Win32/File.hsc +33/−17
- System/Win32/FileMapping.hsc +1/−0
- System/Win32/Info.hsc +32/−16
- System/Win32/Path.hsc +57/−0
- System/Win32/Process.hsc +6/−0
- System/Win32/Types.hs +23/−6
- Win32.cabal +5/−4
Graphics/Win32/Window.hsc view
@@ -25,6 +25,7 @@ import Foreign.Marshal.Alloc (allocaBytes) import Foreign.Ptr (FunPtr, Ptr, castFunPtrToPtr, castPtr, nullPtr) import Foreign.Storable (pokeByteOff)+import Foreign.C.Types (CIntPtr(..)) import Graphics.Win32.GDI.Types (HBITMAP, HCURSOR, HDC, HDWP, HRGN, HWND, PRGN) import Graphics.Win32.GDI.Types (HBRUSH, HICON, HMENU, prim_ChildWindowFromPoint) import Graphics.Win32.GDI.Types (LPRECT, RECT, allocaRECT, peekRECT, withRECT)
System/Win32/File.hsc view
@@ -47,23 +47,38 @@ gENERIC_NONE = 0 #{enum AccessMode,- , gENERIC_READ = GENERIC_READ- , gENERIC_WRITE = GENERIC_WRITE- , gENERIC_EXECUTE = GENERIC_EXECUTE- , gENERIC_ALL = GENERIC_ALL- , dELETE = DELETE- , rEAD_CONTROL = READ_CONTROL- , wRITE_DAC = WRITE_DAC- , wRITE_OWNER = WRITE_OWNER- , sYNCHRONIZE = SYNCHRONIZE- , sTANDARD_RIGHTS_REQUIRED = STANDARD_RIGHTS_REQUIRED- , sTANDARD_RIGHTS_READ = STANDARD_RIGHTS_READ- , sTANDARD_RIGHTS_WRITE = STANDARD_RIGHTS_WRITE- , sTANDARD_RIGHTS_EXECUTE = STANDARD_RIGHTS_EXECUTE- , sTANDARD_RIGHTS_ALL = STANDARD_RIGHTS_ALL- , sPECIFIC_RIGHTS_ALL = SPECIFIC_RIGHTS_ALL- , aCCESS_SYSTEM_SECURITY = ACCESS_SYSTEM_SECURITY- , mAXIMUM_ALLOWED = MAXIMUM_ALLOWED+ , gENERIC_READ = GENERIC_READ+ , gENERIC_WRITE = GENERIC_WRITE+ , gENERIC_EXECUTE = GENERIC_EXECUTE+ , gENERIC_ALL = GENERIC_ALL+ , dELETE = DELETE+ , rEAD_CONTROL = READ_CONTROL+ , wRITE_DAC = WRITE_DAC+ , wRITE_OWNER = WRITE_OWNER+ , sYNCHRONIZE = SYNCHRONIZE+ , sTANDARD_RIGHTS_REQUIRED = STANDARD_RIGHTS_REQUIRED+ , sTANDARD_RIGHTS_READ = STANDARD_RIGHTS_READ+ , sTANDARD_RIGHTS_WRITE = STANDARD_RIGHTS_WRITE+ , sTANDARD_RIGHTS_EXECUTE = STANDARD_RIGHTS_EXECUTE+ , sTANDARD_RIGHTS_ALL = STANDARD_RIGHTS_ALL+ , sPECIFIC_RIGHTS_ALL = SPECIFIC_RIGHTS_ALL+ , aCCESS_SYSTEM_SECURITY = ACCESS_SYSTEM_SECURITY+ , mAXIMUM_ALLOWED = MAXIMUM_ALLOWED+ , fILE_ADD_FILE = FILE_ADD_FILE+ , fILE_ADD_SUBDIRECTORY = FILE_ADD_SUBDIRECTORY+ , fILE_ALL_ACCESS = FILE_ALL_ACCESS+ , fILE_APPEND_DATA = FILE_APPEND_DATA+ , fILE_CREATE_PIPE_INSTANCE = FILE_CREATE_PIPE_INSTANCE+ , fILE_DELETE_CHILD = FILE_DELETE_CHILD+ , fILE_EXECUTE = FILE_EXECUTE+ , fILE_LIST_DIRECTORY = FILE_LIST_DIRECTORY+ , fILE_READ_ATTRIBUTES = FILE_READ_ATTRIBUTES+ , fILE_READ_DATA = FILE_READ_DATA+ , fILE_READ_EA = FILE_READ_EA+ , fILE_TRAVERSE = FILE_TRAVERSE+ , fILE_WRITE_ATTRIBUTES = FILE_WRITE_ATTRIBUTES+ , fILE_WRITE_DATA = FILE_WRITE_DATA+ , fILE_WRITE_EA = FILE_WRITE_EA } ----------------------------------------------------------------@@ -104,6 +119,7 @@ , fILE_ATTRIBUTE_NORMAL = FILE_ATTRIBUTE_NORMAL , fILE_ATTRIBUTE_TEMPORARY = FILE_ATTRIBUTE_TEMPORARY , fILE_ATTRIBUTE_COMPRESSED = FILE_ATTRIBUTE_COMPRESSED+ , fILE_ATTRIBUTE_REPARSE_POINT = FILE_ATTRIBUTE_REPARSE_POINT , fILE_FLAG_WRITE_THROUGH = FILE_FLAG_WRITE_THROUGH , fILE_FLAG_OVERLAPPED = FILE_FLAG_OVERLAPPED , fILE_FLAG_NO_BUFFERING = FILE_FLAG_NO_BUFFERING
System/Win32/FileMapping.hsc view
@@ -28,6 +28,7 @@ import Data.ByteString.Internal ( fromForeignPtr ) import Foreign ( Ptr, nullPtr, plusPtr, maybeWith, FunPtr , ForeignPtr, newForeignPtr )+import Foreign.C.Types (CUIntPtr(..)) ##include "windows_cconv.h"
System/Win32/Info.hsc view
@@ -21,12 +21,13 @@ import Control.Exception (catch) import Foreign.Marshal.Alloc (alloca)+import Foreign.Marshal.Utils (with) import Foreign.Marshal.Array (allocaArray) import Foreign.Ptr (Ptr, nullPtr) import Foreign.Storable (Storable(..)) import System.IO.Error (isDoesNotExistError)-import System.Win32.Types (DWORD, LPCTSTR, LPTSTR, LPVOID, UINT, WORD)-import System.Win32.Types (failIfZero, peekTStringLen, withTString)+import System.Win32.Types (DWORD, LPDWORD, LPCTSTR, LPTSTR, LPVOID, UINT, WORD)+import System.Win32.Types (failIfFalse_, peekTStringLen, withTString, try) #if !MIN_VERSION_base(4,6,0) import Prelude hiding (catch)@@ -118,6 +119,18 @@ try "getFullPathName" (\buf len -> c_GetFullPathName c_name len buf nullPtr) 512 +getLongPathName :: FilePath -> IO FilePath+getLongPathName name = do+ withTString name $ \ c_name ->+ try "getLongPathName"+ (c_GetLongPathName c_name) 512++getShortPathName :: FilePath -> IO FilePath+getShortPathName name = do+ withTString name $ \ c_name ->+ try "getShortPathName"+ (c_GetShortPathName c_name) 512+ searchPath :: Maybe String -> FilePath -> String -> IO (Maybe FilePath) searchPath path filename ext = maybe ($ nullPtr) withTString path $ \p_path ->@@ -131,20 +144,6 @@ then return Nothing else ioError e --- Support for API calls that are passed a fixed-size buffer and tell--- you via the return value if the buffer was too small. In that--- case, we double the buffer size and try again.-try :: String -> (LPTSTR -> UINT -> IO UINT) -> UINT -> IO String-try loc f n = do- e <- allocaArray (fromIntegral n) $ \lptstr -> do- r <- failIfZero loc $ f lptstr n- if (r > n) then return (Left r) else do- str <- peekTStringLen (lptstr, fromIntegral r)- return (Right str)- case e of- Left n -> try loc f n- Right str -> return str- foreign import WINDOWS_CCONV unsafe "GetWindowsDirectoryW" c_getWindowsDirectory :: LPTSTR -> UINT -> IO UINT @@ -160,6 +159,12 @@ foreign import WINDOWS_CCONV unsafe "GetFullPathNameW" c_GetFullPathName :: LPCTSTR -> DWORD -> LPTSTR -> Ptr LPTSTR -> IO DWORD +foreign import WINDOWS_CCONV unsafe "GetLongPathNameW"+ c_GetLongPathName :: LPCTSTR -> LPTSTR -> DWORD -> IO DWORD++foreign import WINDOWS_CCONV unsafe "GetShortPathNameW"+ c_GetShortPathName :: LPCTSTR -> LPTSTR -> DWORD -> IO DWORD+ foreign import WINDOWS_CCONV unsafe "SearchPathW" c_SearchPath :: LPCTSTR -> LPCTSTR -> LPCTSTR -> DWORD -> LPTSTR -> Ptr LPTSTR -> IO DWORD@@ -351,6 +356,17 @@ ---------------------------------------------------------------- -- %fun GetUserName :: IO String++foreign import WINDOWS_CCONV unsafe "windows.h GetUserNameW"+ c_GetUserName :: LPTSTR -> LPDWORD -> IO Bool+ +getUserName :: IO String+getUserName = + allocaArray 512 $ \ c_str -> + with 512 $ \ c_len -> do+ failIfFalse_ "GetUserName" $ c_GetUserName c_str c_len+ len <- peek c_len+ peekTStringLen (c_str, fromIntegral len - 1) ---------------------------------------------------------------- -- Version Info
+ System/Win32/Path.hsc view
@@ -0,0 +1,57 @@+#if __GLASGOW_HASKELL__ >= 709+{-# LANGUAGE Safe #-}+#elif __GLASGOW_HASKELL__ >= 701+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module : System.Win32.Path+-- Copyright : (c) Tamar Christina, 1997-2003+-- License : BSD-style (see the file libraries/base/LICENSE)+--+-- Maintainer : Tamar Christina <tamar@zhox.com>+-- Stability : provisional+-- Portability : portable+--+-- A collection of FFI declarations for interfacing with Win32.+--+-----------------------------------------------------------------------------++module System.Win32.Path (+ filepathRelativePathTo+ , pathRelativePathTo+ ) where++import System.Win32.Types+import System.Win32.File++import Foreign++##include "windows_cconv.h"++#include <windows.h>++filepathRelativePathTo :: FilePath -> FilePath -> IO FilePath+filepathRelativePathTo from to =+ withTString from $ \p_from ->+ withTString to $ \p_to ->+ allocaArray ((#const MAX_PATH) * (#size TCHAR)) $ \p_AbsPath -> do+ _ <- failIfZero "PathRelativePathTo" (c_pathRelativePathTo p_AbsPath p_from fILE_ATTRIBUTE_DIRECTORY+ p_to fILE_ATTRIBUTE_NORMAL)+ path <- peekTString p_AbsPath+ _ <- localFree p_AbsPath+ return path++pathRelativePathTo :: FilePath -> FileAttributeOrFlag -> FilePath -> FileAttributeOrFlag -> IO FilePath+pathRelativePathTo from from_attr to to_attr =+ withTString from $ \p_from ->+ withTString to $ \p_to ->+ allocaArray ((#const MAX_PATH) * (#size TCHAR)) $ \p_AbsPath -> do+ _ <- failIfZero "PathRelativePathTo" (c_pathRelativePathTo p_AbsPath p_from from_attr+ p_to to_attr)+ path <- peekTString p_AbsPath+ _ <- localFree p_AbsPath+ return path++foreign import WINDOWS_CCONV unsafe "Shlwapi.h PathRelativePathToW" + c_pathRelativePathTo :: LPTSTR -> LPCTSTR -> DWORD -> LPCTSTR -> DWORD -> IO UINT
System/Win32/Process.hsc view
@@ -69,6 +69,12 @@ getProcessId :: ProcessHandle -> IO ProcessId getProcessId h = failIfZero "GetProcessId" $ c_GetProcessId h +foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentProcessId"+ c_GetCurrentProcessId :: IO ProcessId++getCurrentProcessId :: IO ProcessId+getCurrentProcessId = c_GetCurrentProcessId+ type Th32SnapHandle = HANDLE type Th32SnapFlags = DWORD -- | ProcessId, number of threads, parent ProcessId, process base priority, path of executable file
System/Win32/Types.hs view
@@ -29,9 +29,10 @@ import Foreign.C.Error (getErrno, errnoToIOError) import Foreign.C.String (newCWString, withCWStringLen) import Foreign.C.String (peekCWString, peekCWStringLen, withCWString)-import Foreign.C.Types (CChar, CUChar, CWchar)+import Foreign.C.Types (CChar, CUChar, CWchar, CIntPtr, CUIntPtr) import Foreign.ForeignPtr (ForeignPtr, newForeignPtr, newForeignPtr_) import Foreign.Ptr (FunPtr, Ptr, nullPtr)+import Foreign (allocaArray) import Numeric (showHex) import System.IO.Error (ioeSetErrorString) import System.IO.Unsafe (unsafePerformIO)@@ -72,6 +73,8 @@ type LARGE_INTEGER = Int64 type UINT_PTR = Word+type LONG_PTR = CIntPtr+type ULONG_PTR = CUIntPtr -- Not really a basic type, but used in many places type DDWORD = Word64@@ -81,11 +84,11 @@ type MbString = Maybe String type MbINT = Maybe INT -type ATOM = UINT-type WPARAM = UINT-type LPARAM = LONG-type LRESULT = LONG-type SIZE_T = DWORD+type ATOM = WORD+type WPARAM = UINT_PTR+type LPARAM = LONG_PTR+type LRESULT = LONG_PTR+type SIZE_T = ULONG_PTR type MbATOM = Maybe ATOM @@ -264,6 +267,20 @@ dwordsToDdword:: (DWORD,DWORD) -> DDWORD dwordsToDdword (hi,low) = (fromIntegral low) .|. (fromIntegral hi `shiftL` finiteBitSize hi) +-- Support for API calls that are passed a fixed-size buffer and tell+-- you via the return value if the buffer was too small. In that+-- case, we double the buffer size and try again.+try :: String -> (LPTSTR -> UINT -> IO UINT) -> UINT -> IO String+try loc f n = do+ e <- allocaArray (fromIntegral n) $ \lptstr -> do+ r <- failIfZero loc $ f lptstr n+ if (r > n) then return (Left r) else do+ str <- peekTStringLen (lptstr, fromIntegral r)+ return (Right str)+ case e of+ Left n -> try loc f n+ Right str -> return str+ ---------------------------------------------------------------- -- Primitives ----------------------------------------------------------------
Win32.cabal view
@@ -1,5 +1,5 @@ name: Win32-version: 2.3.1.1+version: 2.4.0.0 license: BSD3 license-file: LICENSE author: Alastair Reid@@ -14,7 +14,7 @@ cabal-version: >=1.6 extra-source-files: include/diatemp.h include/dumpBMP.h include/ellipse.h include/errors.h- include/Win32Aux.h include/win32debug.h include/windows_cconv.h+ include/Win32Aux.h include/win32debug.h Library build-depends: base >= 4.5 && < 5, bytestring@@ -49,6 +49,7 @@ System.Win32.File System.Win32.FileMapping System.Win32.Info+ System.Win32.Path System.Win32.Mem System.Win32.NLS System.Win32.Process@@ -63,10 +64,10 @@ if impl(ghc >= 7.1) extensions: NondecreasingIndentation extra-libraries:- "user32", "gdi32", "winmm", "advapi32", "shell32", "shfolder"+ "user32", "gdi32", "winmm", "advapi32", "shell32", "shfolder", "shlwapi" include-dirs: include includes: "HsWin32.h", "HsGDI.h", "WndProc.h"- install-includes: "HsWin32.h", "HsGDI.h", "WndProc.h"+ install-includes: "HsWin32.h", "HsGDI.h", "WndProc.h", "windows_cconv.h" c-sources: cbits/HsGDI.c cbits/HsWin32.c