[Haskell-cafe] A function callable from C

Stefan O'Rear stefanor at cox.net
Mon Feb 5 20:37:33 EST 2007


On Tue, Feb 06, 2007 at 12:33:58PM +1100, John Ky wrote:
> Hi,
> 
> The following code works:
> 
> >type ServiceMainClosure = DWORD -> IO ()
> >
> >foreign import ccall "wrapper"
> >  mkServiceMainClosure :: ServiceMainClosure -> IO (FunPtr
> ServiceMainClosure)
> 
> But the following doesn't:
> 
> >type ServiceMainClosure = DWORD -> [String] -> IO ()
> >
> >foreign import ccall "wrapper"
> >  mkServiceMainClosure :: ServiceMainClosure -> IO (FunPtr
> ServiceMainClosure)
> 
> System\Win32\Service.hsc:108:8: parse error on input `import'
> 
> What can I do to get this to work?

You have to use a type that C's tiny brain understains. IANAWP
but I'm guessing you want:

type ServiceMainClosure = DWORD -> Ptr (Ptr CChar) -> IO ()

foreign import ccall "wrapper"
  mkServiceMainClosure :: ServiceMainClosure -> IO (FunPtr ServiceMainClosure)


More information about the Haskell-Cafe mailing list