Pointers to native classes should _not_ be dereferenced by C# #1115
Description
Actual behavior
The GdipDeleteRegion
method gets a friendly overload that takes ref GpRegion
instead of GpRegion*
.
This might be fine, except that GpRegion*
should never be dereferenced, since it's a pointer to a class on the C++ side. The struct defined in the metadata has an IntPtr
field, but unlike HWND where that is just a copyable opaque value, GpRegion
(and other GDI+ structs) actually represent C++ classes, and the 'field' in these structs is misleading. What would really be at that memory location is the first field in the C++ class, so copying around the struct in C# would lead to data corruption as anyone that re-takes the pointer to the struct would expect the full class fields where the struct is, and they wouldn't be there.
Expected behavior
Any extern methods that take a pointer to a native object should not have friendly overloads that replace the pointer with ref
or other modifiers.