Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rickbrew committed Nov 29, 2022
1 parent b87a318 commit 925e83b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ public string? TryGetPropertyName(int index)

`CastPtr<...>` is also provided, which can be used to generate static `__cast()` "method operators." This solves the problem where you have (e.g.) an `ID2D1SolidColorBrush*` that you need to pass to a method that takes a pointer to a base interface, such as `ID2D1Brush*` or even `IUnknown*`. C# does not have struct inheritance, so all of the COM interface structs in [TerraFX.Interop.Windows](https://github.com/terrafx/terrafx.interop.windows) are unrelated as far as it can tell.

Instead of forcing a pointer cast with `(ID2D1Brush*)`, which denies the compiler a chance to verify that the cast is safe, you can use `__cast(p)` (along with an appropriate `using static` declaration). A temporary `CastPtr<ID2D1SolidColorBrush, ID2D1Brush, ID2D1Resource, IUnknown>` will be created which will implicitly cast to pointers of all of those base interface pointer types. (Note that "interface" in this case refers to a COM interface, not a managed interface.) The generation of these `__cast()` operators is not yet provided by this package, but is currently prototyped in the Paint.NET codebase to help with my use of [TerraFX.Interop.Windows](https://github.com/terrafx/terrafx.interop.windows).
Instead of forcing a pointer cast with `(ID2D1Brush*)`, which denies the compiler a chance to verify that the cast is safe, you can use `__cast(p)` (along with an appropriate `using static` declaration). A temporary `CastPtr<ID2D1SolidColorBrush, ID2D1Brush, ID2D1Resource, IUnknown>` will be created which will implicitly cast to pointers of all of those base interface pointer types. (Note that "interface" in this case refers to a COM interface, not a managed interface.) The generation of these `__cast()` operators is not provided by this package, but you can see the [PointerToolkit.TerraFX.Interop.Windows](https://github.com/rickbrew/PointerToolkit.TerraFX.Interop.Windows) package for a real world example.

0 comments on commit 925e83b

Please sign in to comment.