View difference between Paste ID: Kb1ngZ00 and GJN7dwW2
SHOW: | | - or go back to the newest paste.
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
27+
  invokeFunction dll "fmi2GetVersion" c_funcRetString peekCString >>= putStrLn . show
28-
  invokeFunction dll "x2" c_funcRetString peekCString >>= putStrLn . show
28+
  invokeFunction dll "fmi2GetTypesPlatform" c_funcRetString peekCString >>= putStrLn . show
29-
  instantiateFunc <- getProcAddress dll "x3"
29+
  instantiateFunc <- getProcAddress dll "fmi2Instantiate"
30-
  instantiateRet <- c_funcInstantiate (castPtrToFunPtr instantiateFunc) (newCString "t1") (newCString "t2") dll
30+
  t1 <- withCString "t1"
31
  t2 <- withCString "t2"
32
  instantiateRet <- c_funcInstantiate (castPtrToFunPtr instantiateFunc) t1 t2 dll
33
  putStrLn . show $ 1
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' …
34+
35-
    Expected type: CString
35+
36-
      Actual type: IO CString
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-
    In the second argument of `c_funcInstantiate', namely
37+
                with actual type `(CString -> IO a0) -> IO a0'
38-
      `(newCString "t1")'
38+
    Probable cause: `withCString' is applied to too few arguments
39-
    In a stmt of a 'do' block:
39+
    In a stmt of a 'do' block: t1 <- withCString "t1"
40-
      instantiateRet <- c_funcInstantiate
40+
    In the expression:
41-
                          (castPtrToFunPtr instantiateFunc)
41+
      do { dll <- loadLibrary $ head dllNames;
42-
                          (newCString "t1")
42+
           invokeFunction dll "fmi2GetVersion" c_funcRetString peekCString
43-
                          (newCString "t2")
43+
           >>= putStrLn . show;
44-
                          dll
44+
           invokeFunction
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' …
45+
             dll "fmi2GetTypesPlatform" c_funcRetString peekCString
46-
    Expected type: CString
46+
           >>= putStrLn . show;
47-
      Actual type: IO CString
47+
           instantiateFunc <- getProcAddress dll "fmi2Instantiate";
48-
    In the third argument of `c_funcInstantiate', namely
48+
           .... }
49-
      `(newCString "t2")'
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-
    In a stmt of a 'do' block:
50+
                with actual type `(CString -> IO a1) -> IO a1'
51-
      instantiateRet <- c_funcInstantiate
51+
    Probable cause: `withCString' is applied to too few arguments
52-
                          (castPtrToFunPtr instantiateFunc)
52+
    In a stmt of a 'do' block: t2 <- withCString "t2"
53-
                          (newCString "t1")
53+
    In the expression:
54-
                          (newCString "t2")
54+
      do { dll <- loadLibrary $ head dllNames;
55-
                          dll
55+
           invokeFunction dll "fmi2GetVersion" c_funcRetString peekCString
56-
Compilation failed.
56+
           >>= putStrLn . show;
57
           invokeFunction
58
             dll "fmi2GetTypesPlatform" c_funcRetString peekCString
59
           >>= putStrLn . show;
60
           instantiateFunc <- getProcAddress dll "fmi2Instantiate";
61
           .... }
62
Compilation failed