You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've talked about this on Discord, but having an issue will make this easier to track.
COM interfaces have inheritance relationships, e.g. ID2D1SolidColorBrush inherits from ID2D1Brush, then ID2D1Resource, then IUnknown. In native code you can pass an ID2D1SolidColorBrush* to a method that takes an ID2D1Brush* and it works fine. With C# / TerraFX, you have to cast the pointer every time you do this. The cast is safe, but the compiler can't verify that, and you can easily do the wrong thing such as casting ID2D1Bitmap* to ID2D1Brush*. It'll crash spectacularly at runtime, but nothing at compile-time.
Making this work in TerraFX would be an uphill battle since C# doesn't have any way of making this work, other than maybe auto-generating e.g. struct PIUnknown { IUnknown *p; } wrappers for every interface along with the proper cast operators. And then all your code has to use these in place of pointers, but also needs to use the real pointers at ABI boundaries.
TerraFX doesn't need to include these wrappers and the casting operators, but I could generate them on my own for my own project. However, I can't do that without the inheritance information, which doesn't exist.
So, something like this would be nice in TerraFX:
[NativeInheritance(typeof(ID2D1Brush))]
public struct ID2D1SolidColorBrush
{
...
}
Then I can experiment with code-genning my own solutions to this. Anything easily accessible via standard reflection should work.
Some interfaces have multiple interfaces they derive from. Those can be handled by using additional [NativeInheritance(...)]'s.
I'd prefer typeof over strings, e.g. [NativeInheritance("ID2D1Brush")]
The text was updated successfully, but these errors were encountered:
rickbrew
added
proposal
An issue that represents a proposed feature or change to the repo.
untriaged
An issue that has not been triaged by the repo maintainers.
labels
Sep 7, 2021
We've talked about this on Discord, but having an issue will make this easier to track.
COM interfaces have inheritance relationships, e.g.
ID2D1SolidColorBrush
inherits fromID2D1Brush
, thenID2D1Resource
, thenIUnknown
. In native code you can pass anID2D1SolidColorBrush*
to a method that takes anID2D1Brush*
and it works fine. With C# / TerraFX, you have to cast the pointer every time you do this. The cast is safe, but the compiler can't verify that, and you can easily do the wrong thing such as castingID2D1Bitmap*
toID2D1Brush*
. It'll crash spectacularly at runtime, but nothing at compile-time.Making this work in TerraFX would be an uphill battle since C# doesn't have any way of making this work, other than maybe auto-generating e.g.
struct PIUnknown { IUnknown *p; }
wrappers for every interface along with the proper cast operators. And then all your code has to use these in place of pointers, but also needs to use the real pointers at ABI boundaries.TerraFX doesn't need to include these wrappers and the casting operators, but I could generate them on my own for my own project. However, I can't do that without the inheritance information, which doesn't exist.
So, something like this would be nice in TerraFX:
Then I can experiment with code-genning my own solutions to this. Anything easily accessible via standard reflection should work.
Some interfaces have multiple interfaces they derive from. Those can be handled by using additional
[NativeInheritance(...)]
's.I'd prefer
typeof
over strings, e.g.[NativeInheritance("ID2D1Brush")]
The text was updated successfully, but these errors were encountered: