IntPtr GetHandle(object obj) { if (obj == null) return IntPtr.Zero; return GCHandle.ToIntPtr(GCHandle.Alloc(obj, GCHandleType.Pinned)); }