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

User32.EndPaint overload should pass argument by reference #298

Closed dbremner closed 8 years ago

dbremner commented 8 years ago

User32.EndPaint(System.IntPtr hWnd, PInvoke.User32.PAINTSTRUCT lpPaint) function should pass its second argument as a ref. I noticed this while updating a project to 0.3.152. The associated pull request works around the problem by changing the Friendly attribute from FriendlyFlag.In to FriendlyFlag.Bidirectional.

AArnott commented 8 years ago

I'm guessing the "should pass its second argument as a ref" is only a perf optimization. And in that case, that's why the primary p/invoke signature we write for many of these methods takes a pointer:

private unsafe void SomeFunc() {
  PAINTSTRUCT ps; // initialized elsewhere.
  User32.EndPaint(hwnd, &ps);
}

If ref really is so much more convenient than the pointer approach (I'd like to learn how that is) then the caller can define a helper method that wraps the pointer usage.