Passing myself, a struct, as a C callback context
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 30 02:12:55 PDT 2015
On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote:
> I'm registering a callback with some C code. The simplified
> story is
> here, but the actual code is on GitHub [1] at the end if you
> care.
>
> The call looks something like this.
>
> void register(void(*fp)(void*), void* context);
>
> I have a class that holds state for the callback and registers
> itself:
>
> final class Klass
> {
> void method()
> {
> register(callback_function, &this);
> }
> }
`this` is already a reference. You're taking the address of that
reference. A simple cast should work: `cast(void*) this`.
More information about the Digitalmars-d-learn
mailing list