1{- | 2 Module : System.Win32.String 3 Copyright : 2013 shelarcy 4 License : BSD-style 5 6 Maintainer : shelarcy@gmail.com 7 Stability : Provisional 8 Portability : Non-portable (Win32 API) 9 10 Utilities for primitive marshalling of Windows' C strings. 11-} 12module System.Win32.String 13 ( LPSTR, LPCSTR, LPWSTR, LPCWSTR 14 , TCHAR, LPTSTR, LPCTSTR, LPCTSTR_ 15 , withTString, withTStringLen, peekTString, peekTStringLen 16 , newTString 17 , withTStringBuffer, withTStringBufferLen 18 ) where 19import System.Win32.Types 20 21-- | Marshal a dummy Haskell string into a NUL terminated C wide string 22-- using temporary storage. 23-- 24-- * the Haskell string is created by length parameter. And the Haskell 25-- string contains /only/ NUL characters. 26-- 27-- * the memory is freed when the subcomputation terminates (either 28-- normally or via an exception), so the pointer to the temporary 29-- storage must /not/ be used after this. 30-- 31withTStringBuffer :: Int -> (LPTSTR -> IO a) -> IO a 32withTStringBuffer maxLength 33 = let dummyBuffer = replicate maxLength '\0' 34 in withTString dummyBuffer 35 36-- | Marshal a dummy Haskell string into a C wide string (i.e. wide 37-- character array) in temporary storage, with explicit length 38-- information. 39-- 40-- * the Haskell string is created by length parameter. And the Haskell 41-- string contains /only/ NUL characters. 42-- 43-- * the memory is freed when the subcomputation terminates (either 44-- normally or via an exception), so the pointer to the temporary 45-- storage must /not/ be used after this. 46-- 47withTStringBufferLen :: Int -> ((LPTSTR, Int) -> IO a) -> IO a 48withTStringBufferLen maxLength 49 = let dummyBuffer = replicate maxLength '\0' 50 in withTStringLen dummyBuffer 51 52