{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TemplateHaskell #-}
module System.Win32.Error.Types where
import Control.Exception
import Data.Text
import Data.Typeable
import Foreign
import System.Win32.Types (DWORD)
import System.Win32.Error.TH
Int -> ErrCode -> ShowS
[ErrCode] -> ShowS
ErrCode -> String
ErrCode -> ErrCode -> Bool
(Int -> ErrCode -> ShowS)
-> (ErrCode -> String) -> ([ErrCode] -> ShowS) -> Show ErrCode
(ErrCode -> ErrCode -> Bool)
-> (ErrCode -> ErrCode -> Bool) -> Eq ErrCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrCode] -> ShowS
$cshowList :: [ErrCode] -> ShowS
show :: ErrCode -> String
$cshow :: ErrCode -> String
showsPrec :: Int -> ErrCode -> ShowS
$cshowsPrec :: Int -> ErrCode -> ShowS
/= :: ErrCode -> ErrCode -> Bool
$c/= :: ErrCode -> ErrCode -> Bool
== :: ErrCode -> ErrCode -> Bool
$c== :: ErrCode -> ErrCode -> Bool
genErrCode
ErrCode -> DWORD
gentoDWORD
DWORD -> ErrCode
genfromDWORD
instance Storable ErrCode where
sizeOf :: ErrCode -> Int
sizeOf _ = DWORD -> Int
forall a. Storable a => a -> Int
sizeOf (DWORD
forall a. HasCallStack => a
undefined :: DWORD)
alignment :: ErrCode -> Int
alignment _ = DWORD -> Int
forall a. Storable a => a -> Int
alignment (DWORD
forall a. HasCallStack => a
undefined :: DWORD)
peek :: Ptr ErrCode -> IO ErrCode
peek ptr :: Ptr ErrCode
ptr = (Ptr DWORD -> IO DWORD
forall a. Storable a => Ptr a -> IO a
peek (Ptr DWORD -> IO DWORD)
-> (Ptr ErrCode -> Ptr DWORD) -> Ptr ErrCode -> IO DWORD
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr ErrCode -> Ptr DWORD
forall a b. Ptr a -> Ptr b
castPtr) Ptr ErrCode
ptr IO DWORD -> (DWORD -> IO ErrCode) -> IO ErrCode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ErrCode -> IO ErrCode
forall (m :: * -> *) a. Monad m => a -> m a
return (ErrCode -> IO ErrCode)
-> (DWORD -> ErrCode) -> DWORD -> IO ErrCode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DWORD -> ErrCode
fromDWORD
poke :: Ptr ErrCode -> ErrCode -> IO ()
poke ptr :: Ptr ErrCode
ptr ec :: ErrCode
ec = Ptr DWORD -> DWORD -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr ErrCode -> Ptr DWORD
forall a b. Ptr a -> Ptr b
castPtr Ptr ErrCode
ptr) (ErrCode -> DWORD
toDWORD ErrCode
ec)
data Win32Exception = Win32Exception
{ Win32Exception -> Text
function :: Text
, Win32Exception -> ErrCode
errCode :: ErrCode
, Win32Exception -> Text
systemMessage :: Text
} deriving (Typeable, Int -> Win32Exception -> ShowS
[Win32Exception] -> ShowS
Win32Exception -> String
(Int -> Win32Exception -> ShowS)
-> (Win32Exception -> String)
-> ([Win32Exception] -> ShowS)
-> Show Win32Exception
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Win32Exception] -> ShowS
$cshowList :: [Win32Exception] -> ShowS
show :: Win32Exception -> String
$cshow :: Win32Exception -> String
showsPrec :: Int -> Win32Exception -> ShowS
$cshowsPrec :: Int -> Win32Exception -> ShowS
Show)
instance Exception Win32Exception
tryWin32 :: IO a -> IO (Either Win32Exception a)
tryWin32 :: IO a -> IO (Either Win32Exception a)
tryWin32 = IO a -> IO (Either Win32Exception a)
forall e a. Exception e => IO a -> IO (Either e a)
try