module Utils where
import Control.Applicative
import Control.Monad (unless)
import Foreign
import System.Win32.Types
freeptr :: (Ptr b -> IO ()) -> Ptr (Ptr a) -> IO ()
freeptr rpcfree pptr =
peek pptr >>= \ptr ->
unless (ptr == nullPtr) $ do
rpcfree $ castPtr ptr
poke pptr nullPtr
peekMaybeTString :: LPTSTR -> IO (Maybe String)
peekMaybeTString ptr
| ptr == nullPtr = return Nothing
| otherwise = Just <$> peekTString ptr
withMaybeTString :: Maybe String -> (LPTSTR -> IO a) -> IO a
withMaybeTString Nothing f = f nullPtr
withMaybeTString (Just str) f = withTString str f