Closed arlm closed 1 year ago
Thanks for starting this. I've wondered how to track this. :)
You are welcome. There are some generic tasks also:
ref
and out
parameters to pointersStringBuffer
parameters to char*
pointersint
typestatic Create()
methods on structs
Change all ref and out parameters to pointers
This one could use some discussion first, I think. While use of [Friendly]
certainly brings back those convenient keywords, if no caller is ever conceivably going to use the pointer version, I'm ok with just using ref
or out
in the primary definition. For example, if it's a flags enum passed by ref
so the method can adjust flags for the caller to see, I can't imagine a pointer would ever be useful in that case. It's just too trivial to think a pointer would be used. But we could certainly review all uses and see if we can get closer to an ideal.
BTW, that probably doesn't need to wait for 2.0. As switching to pointers isn't a breaking change so long as the code generator is applied to recreate the friendly variety.
@arlm Does it mean that I must use pointers in my code to use PInvoke library ?
@NN--- No, the library generates automatically other options for consuming the API without pointers with the use of the [Friendly]
attribute during the library codification, which we do on all pointers.
Correct. So for example wherever you see a pointer, you can use IntPtr
. And sometimes char*
gets a StringBuilder
option, etc.
That said, once I had to write a bit of code twice, once with IntPtr and once with pointers, I found the pointer one was much easier to get right.
PInvoke
namespace instead of nested types. This will make 'promoting' them to Windows.Core
or other 'upstream' projects possible with type forwarders.[MarshalAs]
attribute and whose type are also blittable.
This is an issue to register the activities and refactoring needed for the v2 milestone. Here are some: