how to call a callback in a haskell dll

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to call a callback in a haskell dll

Kees Bleijenberg

My program creates a Windows dll. The calling program calls a function with strings as parameters. Works fine.

I want to add a extra parameter. This extra parameter is a callback:  a function Int -> Int: stdcall. In Haskell I want to call this function.  So I have to convert the pointer to a (formal) Haskell function.

In the examples for the FFI, Haskell provides the callback. I need an example or documentation.

 

Kees

 

 


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: how to call a callback in a haskell dll

Donn Cave-4
Quoth "Kees Bleijenberg" <[hidden email]>,
> My program creates a Windows dll. The calling program calls a function with
> strings as parameters. Works fine.
>
> I want to add a extra parameter. This extra parameter is a callback:  a
> function Int -> Int: stdcall. In Haskell I want to call this function.  So I
> have to convert the pointer to a (formal) Haskell function.
>
> In the examples for the FFI, Haskell provides the callback. I need an
> example or documentation.

It's unclear to me whether the Haskell program initially chooses
the function and creates a pointer to it, or that happens in C/C++.
In the former case, I think Foreign.StablePtr serves that purpose.

In the latter case, Haskell will receive the function as something
like FunPtr (CInt -> CInt), and you need a "dynamic" foreign function
to convert the pointer, like
  foreign import ccall "dynamic" iiPtrStub
     :: FunPtr (CInt -> CInt) -> (CInt -> CInt)

That's lightly documented in the library docs under Foreign.Ptr.

        Donn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe