Guest User

Untitled

a guest
May 22nd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE ScopedTypeVariables #-}
  2. module Main(main) where
  3.  
  4. import System.Win32.DLL
  5. import System.Win32.Types as Win32Types
  6. import Foreign.Ptr
  7. import Foreign.C.String
  8. import Foreign.ForeignPtr
  9.  
  10. foreign import ccall "dynamic"
  11.   --c_TestInt :: FunPtr (Int -> IO (Int)) -> Int -> IO (Int)
  12.   c_funcRetString :: FunPtr (IO (CString)) -> IO (CString)
  13. foreign import ccall "dynamic"
  14.   c_funcInstantiate :: FunPtr (CString -> CString -> HMODULE -> IO (Ptr ())) ->  CString -> CString -> HMODULE -> IO (Ptr ())
  15.  
  16. dllNames = ["tank"]
  17.  
  18. invokeFunction dll funcName funcType convType = do
  19.   func <- getProcAddress dll funcName
  20.   ret <- funcType $ castPtrToFunPtr func
  21.   convType ret
  22.  
  23. main :: IO ()
  24.  
  25. main = do
  26.   dll <- loadLibrary $ head dllNames
  27.   invokeFunction dll "x1" c_funcRetString peekCString >>= putStrLn . show
  28.   invokeFunction dll "x2" c_funcRetString peekCString >>= putStrLn . show
  29.   instantiateFunc <- getProcAddress dll "x3"
  30.   instantiateRet <- c_funcInstantiate (castPtrToFunPtr instantiateFunc) (newCString "t1") (newCString "t2") dll
  31.   putStrLn . show $ 1
  32.  
  33.  
  34. C:\source\speciale\r_and_d\source\hs_prototype\dynamic_loading_tank_tankcontroller\main.hs:30:74-88: Couldn't match type `IO CString' with `Ptr Foreign.C.Types.CChar' …
  35.    Expected type: CString
  36.      Actual type: IO CString
  37.    In the second argument of `c_funcInstantiate', namely
  38.       `(newCString "t1")'
  39.    In a stmt of a 'do' block:
  40.      instantiateRet <- c_funcInstantiate
  41.                          (castPtrToFunPtr instantiateFunc)
  42.                          (newCString "t1")
  43.                          (newCString "t2")
  44.                          dll
  45. C:\source\speciale\r_and_d\source\hs_prototype\dynamic_loading_tank_tankcontroller\main.hs:30:92-106: Couldn't match type `IO CString' with `Ptr Foreign.C.Types.CChar'
  46.     Expected type: CString
  47.       Actual type: IO CString
  48.     In the third argument of `c_funcInstantiate', namely
  49.      `(newCString "t2")'
  50.     In a stmt of a 'do' block:
  51.       instantiateRet <- c_funcInstantiate
  52.                           (castPtrToFunPtr instantiateFunc)
  53.                           (newCString "t1")
  54.                           (newCString "t2")
  55.                           dll
  56. Compilation failed.
Advertisement
Add Comment
Please, Sign In to add comment