pass a delegate to an API as a context pointer?
teo
teo.ubuntu at yahoo.com
Tue Jul 3 01:53:29 PDT 2007
teo Wrote:
> Russell Lewis Wrote:
> > Your code below shouldn't work because void* is 4 bytes (a single
> > pointer) whereas a delegate is 8 bytes (two pointers). But you can do this:
>
> So, my only chance is if I wrap the delegate somehow. Thanks Russell.
By the way, I tried to pass the address of the delegate like this:
(for details see my first post in this thread)
void test(foo f)
{
xyz(cast(callback)&handler, cast(void*)&f);
}
Unfortunately I wasn't able to convert it back to delegate later in the callback:
static void handler(void *context)
{
foo f = *(cast(foo*)context);
int i = f(); // call A.abc();
}
It simply crashes. The context value is exactly the same as &f (in test). Any ideas why? Russell? Kirk?
More information about the Digitalmars-d
mailing list