Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ScopedTypeVariables #-}
- module Main(main) where
- import System.Win32.DLL
- import System.Win32.Types as Win32Types
- import Foreign.Ptr
- import Foreign.C.String
- import Foreign.ForeignPtr
- foreign import ccall "dynamic"
- --c_TestInt :: FunPtr (Int -> IO (Int)) -> Int -> IO (Int)
- c_funcRetString :: FunPtr (IO (CString)) -> IO (CString)
- foreign import ccall "dynamic"
- c_funcInstantiate :: FunPtr (CString -> CString -> HMODULE -> IO (Ptr ())) -> CString -> CString -> HMODULE -> IO (Ptr ())
- dllNames = ["tank"]
- invokeFunction dll funcName funcType convType = do
- func <- getProcAddress dll funcName
- ret <- funcType $ castPtrToFunPtr func
- convType ret
- main :: IO ()
- main = do
- dll <- loadLibrary $ head dllNames
- invokeFunction dll "x1" c_funcRetString peekCString >>= putStrLn . show
- invokeFunction dll "x2" c_funcRetString peekCString >>= putStrLn . show
- instantiateFunc <- getProcAddress dll "x3"
- instantiateRet <- c_funcInstantiate (castPtrToFunPtr instantiateFunc) (newCString "t1") (newCString "t2") dll
- putStrLn . show $ 1
- 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' …
- Expected type: CString
- Actual type: IO CString
- In the second argument of `c_funcInstantiate', namely
- `(newCString "t1")'
- In a stmt of a 'do' block:
- instantiateRet <- c_funcInstantiate
- (castPtrToFunPtr instantiateFunc)
- (newCString "t1")
- (newCString "t2")
- dll
- 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' …
- Expected type: CString
- Actual type: IO CString
- In the third argument of `c_funcInstantiate', namely
- `(newCString "t2")'
- In a stmt of a 'do' block:
- instantiateRet <- c_funcInstantiate
- (castPtrToFunPtr instantiateFunc)
- (newCString "t1")
- (newCString "t2")
- dll
- Compilation failed.
Advertisement
Add Comment
Please, Sign In to add comment