-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetStdHandle shouldn't return a CloseHandleSafeHandle #91
Comments
Great point. I filed microsoft/win32metadata#244 against the metadata so we can do this along with other projections. |
Now that #143 is done, we actually can create |
Notice .NET SDK install failure earlier and workaround broken script
I'm curious, how are you expected to pass a handle from GetStdHandle into functions such as GetConsoleMode which expect SafeHandle? Use SafeFileHandle or is there a better way of doing it? var @out = PInvoke.GetStdHandle(Windows.Win32.System.Console.STD_HANDLE.STD_OUTPUT_HANDLE);
var safeHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(@out, ownsHandle: false);
PInvoke.GetConsoleMode(safeHandle, out var mode); |
@xPaw: it's trivial if you call the SafeHandle safeHandle = PInvoke.GetStdHandle_SafeHandle(default);
PInvoke.GetConsoleMode(safeHandle, out var mode); |
Ah that's the trick, thank you. |
Standard output handles should rarely be closed. Here's Raymond Chen's explanation. Thus, the proper way to use
GetStdHandle
is by combining it withDangerousAddRef
:This could be simplified if
GetStdHandle
wouldn't return aCloseHandleSafeHandle
.The text was updated successfully, but these errors were encountered: