wrapping a C style delegate

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 25 16:00:19 PDT 2017


On Friday, 25 August 2017 at 13:49:20 UTC, Kagamin wrote:
> You're not specific enough. What would be semantics of such 
> wrapper?

The C function I'm trying to wrap takes a function pointer which 
is essentially a delegate, but not quite:

ErrorEnum function(Struct* s, void function(Struct*, ErrorEnum 
status, void *userData) callback, void *userData, uint flags) 
SomeAPIaddCallback;

I want to make it a member function of a wrapping struct so I can 
call it like

MyStruct ms = ...

ms.addCallback((ErrorEnum ee) { ... });

instead of

SomeAPIaddCallback(ms.s,(Struct*, ErrorEnum status, void 
*userData) { ... } /*doesn't become a delegate */,null,0);

I'm not sure how to do it.




More information about the Digitalmars-d-learn mailing list