gir.core
gir.core copied to clipboard
Verify UnmanagedCallersOnlyAttribute for callback handlers
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_dataparameter:GCHandle.ToIntPtr(data) - Restore data from
user_dataparameter:GCHandle.FromIntPtr(data).Target - Free data via:
GCHandle.FromIntPtr(data).Free();