Unsafe code needed for casting pointers to IntPtr