Skip to content

Pointers to native classes should _not_ be dereferenced by C# #1115

Open
@AArnott

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.

Metadata

Assignees

No one assigned

    Labels

    blockedThis issue cannot be fixed without first a change to a dependencybugSomething isn't workingmetadata gemA feature of the metadata that cswin32 does not yet utilitzepartner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions