Running a delegate inside a C function

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 16:07:47 PDT 2014


See my answer to this:

http://stackoverflow.com/questions/22845175/pass-delegates-to-external-c-functions-in-d


Since a delegate is two pointers and most C functions expect only 
one pointer, you need to do some kind of magic. There's one 
solution. Another is if the C function can pass a void* argument 
to the callback function, you pass your class that way and 
forward it to the method by casting it back.

But when interacting with C libraries, you should generally use a 
function pointer rather than a delegate.


More information about the Digitalmars-d-learn mailing list