Calling C functions with D function pointers as operands
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat Apr 26 09:20:24 PDT 2008
"Zarathustra" <adam.chrapkowski at gmail.com> wrote in message
news:fuvj7c$1hf7$1 at digitalmars.com...
> How can I call C functions with D function pointers as operands?
>
> I tried this:
> // gl2psUserWritePNG & gl2psUserFlushPNG are static
> void function(png_struct*, ubyte*, uint) gl2psUserWritePNG_ptr
> = &gl2psUserWritePNG;
> void function(png_struct*)
> gl2psUserFlushPNG_ptr = &gl2psUserFlushPNG;
>
> png_set_write_fn(
> png_ptr,
> cast(void*)png,
> gl2psUserFlushPNG_ptr,
> gl2psUserFlushPNG_ptr
> );
>
> but there are some errors:
> Error: cannot implicitly convert expression (gl2psUserWritePNG_ptr)
> of type void function(png_struct*, ubyte*, uint) to voidC function
> (png_struct*, ubyte*, uint)
>
> Error: cannot implicitly convert expression (gl2psUserFlushPNG_ptr)
> of type void function(png_struct*) to voidC function(png_struct*)
You have to declare your callback functions as extern(C), like so:
extern(C) void gl2psUserFlushPNG(png_struct* s)
{
...
}
Same with the other one.
More information about the Digitalmars-d-learn
mailing list