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

Add `kernel32!SetHandleInformation` and `kernel32!GetHandleInformation` #440

Closed mckunda closed 4 years ago

mckunda commented 4 years ago
mckunda commented 4 years ago

@AArnott if you have any ideas on how to test these, please let me know

AArnott commented 4 years ago

Regarding how to test this (which seems like a good idea), you could create a ManualResetEvent in the unit test and then obtain its Handle property, and call the 2 new methods on that handle, just to see if no exception is thrown.

mckunda commented 4 years ago

Thanks for the feedback! Hope I understood you correctly. Also, I'd like to point out two things:

  1. Is it okay that from GetHandleInformation we may get a result that's not defined in HandleFlags, e.g. 0x00000003, which is HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE? Honestly, I don't quite understand that.
  2. Also I don't know if the methods I added are store-banned, because I have no clue how to check that. Could you please explain?
AArnott commented 4 years ago

You can check for store-banned status from the Microsoft API docs for the method: image

So that's a good point: we need to move these methods to the storebanned folder so they don't cause store app rejection.

AArnott commented 4 years ago

Is it okay that from GetHandleInformation we may get a result that's not defined in HandleFlags

Yes: that's the nature of [Flags] enums. Folks would test for individual flags.

mckunda commented 4 years ago

Thanks for the help! Hope now it's all OK.