Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rickbrew authored Dec 4, 2021
1 parent 53a1af9 commit d62c78a
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 @@ -7,7 +7,7 @@ Pointers up to 3 levels of indirection are supported, e.g. `void***` and `T***`.

We may get this in .NET itself someday, if https://github.com/dotnet/runtime/issues/62342 is approved and landed. Until then, you can use this.

`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*`. Instead of forcing a pointer cast with `(ID2D1Brush*)`, which denies the compiler a chance to verify that the cast is appropriate, you can use `__cast(p)`. A temporary `CastPtr<ID2D1SolidColorBrush, ID2D1Brush, ID2D1Resource, IUnknown>` will be created which will implicitly cast to pointers of all the base interface pointer types. (Note that "interface" in the sense refers to a COM interface, not a managed interface.)
`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*`. 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 the 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).

```cs
namespace PointerToolkit;
Expand Down

0 comments on commit d62c78a

Please sign in to comment.