Callback Handlers need to provide a native function which can be called from C.
The UnmanagedCallersOnlyAttribute allows to call a function directly from native code.
Verify if it is possible to improve the handlers. For this to work we need to pass data around which can be done via the user_data parameters of callbacks:
- Pin data via
var data = GCHandle.Alloc(action);
- Pass data via the
user_data parameter: GCHandle.ToIntPtr(data)
- Restore data from
user_data parameter: GCHandle.FromIntPtr(data).Target
- Free data via:
GCHandle.FromIntPtr(data).Free();