Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
219
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 "fmi2GetVersion" c_funcRetString peekCString >>= putStrLn . show
  28.   invokeFunction dll "fmi2GetTypesPlatform" c_funcRetString peekCString >>= putStrLn . show
  29.   instantiateFunc <- getProcAddress dll "fmi2Instantiate"
  30.   t1 <- withCString "t1"
  31.   t2 <- withCString "t2"
  32.   instantiateRet <- c_funcInstantiate (castPtrToFunPtr instantiateFunc) t1 t2 dll
  33.   putStrLn . show $ 1
  34.  
  35.  
  36. C:\source\speciale\r_and_d\source\hs_prototype\dynamic_loading_tank_tankcontroller\main.hs:29:9-24: Couldn't match expected type `IO CString'
  37.                 with actual type `(CString -> IO a0) -> IO a0'
  38.    Probable cause: `withCString' is applied to too few arguments
  39.     In a stmt of a 'do' block: t1 <- withCString "t1"
  40.     In the expression:
  41.       do { dll <- loadLibrary $ head dllNames;
  42.            invokeFunction dll "fmi2GetVersion" c_funcRetString peekCString
  43.            >>= putStrLn . show;
  44.            invokeFunction
  45.              dll "fmi2GetTypesPlatform" c_funcRetString peekCString
  46.            >>= putStrLn . show;
  47.            instantiateFunc <- getProcAddress dll "fmi2Instantiate";
  48.            .... }
  49. C:\source\speciale\r_and_d\source\hs_prototype\dynamic_loading_tank_tankcontroller\main.hs:30:9-24: Couldn't match expected type `IO CString'
  50.                 with actual type `(CString -> IO a1) -> IO a1'
  51.    Probable cause: `withCString' is applied to too few arguments
  52.     In a stmt of a 'do' block: t2 <- withCString "t2"
  53.     In the expression:
  54.       do { dll <- loadLibrary $ head dllNames;
  55.            invokeFunction dll "fmi2GetVersion" c_funcRetString peekCString
  56.            >>= putStrLn . show;
  57.            invokeFunction
  58.              dll "fmi2GetTypesPlatform" c_funcRetString peekCString
  59.            >>= putStrLn . show;
  60.            instantiateFunc <- getProcAddress dll "fmi2Instantiate";
  61.            .... }
  62. Compilation failed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement