still no luck ;-( Everything works well under ghci but if I compile it with ghc I get seg. fault
ghc version 7.6.3
I found out that when I load my ghci without any .o and .hi files ghci function calls works fine. If I then compile my code with ghc and restart my ghci (.o and .hi files now exists) the ghci crashes.
I have tried compiling with:
ghc -O --make Service.hs -L. -lmodel
ghc --make Service.hs -L. -lmodel
ghc -o service Service.hs -L. -lmodel
I have tried to call ffi function with:
setmodulestring1 param value = do
let param = cParamLength = fromIntegral $ length param ::CInt
cValueLength = fromIntegral $ length value ::CInt
setVarInArray = (-1)::CInt
B.useAsCString (B.pack "FilePath") $ \cParam -> do
B.useAsCString (B.pack "C:/dev/misc/haskell/services/FM") $ \cValue -> do
result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray
return result
or with this:
setmodulestring :: String -> String -> IO CInt
setmodulestring param value = do
let param = "FilePath"
let value = "C:/dev/misc/haskell/services/FM"
cParam <- newCString param
cValue <- newCString value
let cParamLength = fromIntegral $ length param ::CInt
cValueLength = fromIntegral $ length value ::CInt
setVarInArray = (-1)::CInt
result <- c_setmodulestring cParam cParamLength cValue cValueLength setVarInArray
free cParam
free cValue
return result
my main is:
main = do
let param = "FilePath"
let value = "C:/dev/misc/haskell/services/FM"
result <- liftIO $ FM.setmodulestring param value
return "done"
and still no luck - works in ghci and crashes as exe
interfacing the same library from a c++ code:
extern "C" int __stdcall setmodulestring(char* param,unsigned int length,char* valuein,unsigned int valuelength,int index);
interfacing it from Haskell:
foreign import ccall "setmodulestring" c_setmodulestring :: CString -> CInt -> CString -> CInt -> CInt -> IO CInt
please any ideas?