Calling delegate in a dll callback fails silently
Andre Pany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 16 15:17:07 PDT 2017
Hi,
my D application uses a Dll written in another language.
In my D code I retrieve the address of a delegate as integer:
int dgRef = cast(int) &(dg);
This integer I pass to a function in the dll together with the
address of a callback function.
extern(C) static void notifyEventCallback(int reference1)
{
if (auto dg = *cast(NotifyEvent*)cast(void*) reference1)
{
writeln("HERE1");
dg(null);
writeln("HERE2");
}
}
The callback function casts the integer back to the delegate
and execute it.
This scenario is working fine if in the dll function the callback
immediatelly is called. But my real scenario is not working.
The dll shows an UI and the callback should be called on a
button press in the UI.
In this scenario the callback is called, the cast is successful
and HERE1 is shown but neither the dg is called (has a dummy
writeln as coding)
nor HERE2 is shown.
I have no idea why the cast can be succesful but the call to
dg(null) is silently
failing. Do you have any idea? Maybe the UI button press runs in
another thread and causes this issue?
Kind regards
André
More information about the Digitalmars-d-learn
mailing list