public static IntPtr Pin <T> (this T[] obj, PinnedObjects ctx) { GCHandle hnd = GCHandle.Alloc(obj, GCHandleType.Pinned); ctx.Handles.Add(hnd); return(hnd.AddrOfPinnedObject()); }
public static IntPtr Pin(this string obj, PinnedObjects ctx) { byte[] n = System.Text.Encoding.UTF8.GetBytes(obj + '\0'); GCHandle hnd = GCHandle.Alloc(n, GCHandleType.Pinned); ctx.Handles.Add(hnd); return(hnd.AddrOfPinnedObject()); }