I using some old API and need to pass the a pointer of a struct to unmanaged code that runs asynchronous.
In other words, after i passing the struct pointer to the unman
How about having the struct include an ActOnMe()
interface and method something like:
delegate void ActByRef(ref T1 p1, ref T2 p2); interface IActOnMe {ActOnMe (ActByRef proc, ref T param);} struct SuperThing : IActOnMe { int this; int that; ... void ActOnMe (ActByRef , ref T param) { proc(ref this, ref param); } }
Because the delegate takes a generic parameter by reference, it should be possible in most cases to avoid the overhead of creating closures by passing a delegate to a static method along with a reference to a struct to carry data to or from that method. Further, casting an already-boxed instance of SuperThing
to IActOnMe
and calling ActOnMe
on it will expose the fields of that boxed instance for updating, as opposed to creating another copy of them as would occur with a typecast to the struct.