dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Codegen should produce friendly string overloads #286

Closed AArnott closed 1 year ago

AArnott commented 8 years ago

As @vbfox said:

Always generating StringBuilder for "out + char" and string for "in + char" seem like good defaults

AArnott commented 4 years ago

Unfortunately generating StringBuilder overloads will be more complicated. It's not possible to get a pointer to its internal buffer (which may not even be contiguous!). The .NET interop marshaler does magic to make it work, which we'll have to re-implement in our 'friendly' methods.

Using string for in parameters is straightforward, but there is exactly one method so far that defines a [Friendly(FriendlyFlags.In | FriendlyFlags.Array)] char* parameter as required to get the new behavior, so we need to audit all the char* parameters that are not decorated to see if they would benefit from the friendly attribute so they get a string overload.

AArnott commented 3 years ago

We should also audit all the extern methods that accept string to consider revising them to use [Friendly(FriendlyFlags.In | FriendlyFlags.Array)] char* instead.