kernel32: Fix last error value of GetStdHandle/SetStdHandle when called with wrong std handle.
This commit is contained in:
parent
297b054e74
commit
9d74a70ad5
|
@ -396,7 +396,7 @@ HANDLE WINAPI GetStdHandle( DWORD std_handle )
|
|||
case STD_OUTPUT_HANDLE: return NtCurrentTeb()->Peb->ProcessParameters->hStdOutput;
|
||||
case STD_ERROR_HANDLE: return NtCurrentTeb()->Peb->ProcessParameters->hStdError;
|
||||
}
|
||||
SetLastError( ERROR_INVALID_PARAMETER );
|
||||
SetLastError( ERROR_INVALID_HANDLE );
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ BOOL WINAPI SetStdHandle( DWORD std_handle, HANDLE handle )
|
|||
case STD_OUTPUT_HANDLE: NtCurrentTeb()->Peb->ProcessParameters->hStdOutput = handle; return TRUE;
|
||||
case STD_ERROR_HANDLE: NtCurrentTeb()->Peb->ProcessParameters->hStdError = handle; return TRUE;
|
||||
}
|
||||
SetLastError( ERROR_INVALID_PARAMETER );
|
||||
SetLastError( ERROR_INVALID_HANDLE );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1134,6 +1134,41 @@ static void test_VerifyConsoleIoHandle(void)
|
|||
ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
|
||||
}
|
||||
|
||||
static void test_GetSetStdHandle(void)
|
||||
{
|
||||
HANDLE handle;
|
||||
DWORD error;
|
||||
BOOL ret;
|
||||
|
||||
/* get invalid std handle */
|
||||
SetLastError(0xdeadbeef);
|
||||
handle = GetStdHandle(42);
|
||||
error = GetLastError();
|
||||
ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
|
||||
"wrong GetLastError() %d\n", error);
|
||||
ok(handle == INVALID_HANDLE_VALUE, "expected INVALID_HANDLE_VALUE\n");
|
||||
|
||||
/* get valid */
|
||||
SetLastError(0xdeadbeef);
|
||||
handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
error = GetLastError();
|
||||
ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
|
||||
|
||||
/* set invalid std handle */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = SetStdHandle(42, handle);
|
||||
error = GetLastError();
|
||||
ok(!ret, "expected SetStdHandle to fail\n");
|
||||
ok(error == ERROR_INVALID_HANDLE || broken(error == ERROR_INVALID_FUNCTION)/* Win9x */,
|
||||
"wrong GetLastError() %d\n", error);
|
||||
|
||||
/* set valid (restore old value) */
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = SetStdHandle(STD_INPUT_HANDLE, handle);
|
||||
error = GetLastError();
|
||||
ok(ret, "expected SetStdHandle to succeed\n");
|
||||
ok(error == 0xdeadbeef, "wrong GetLastError() %d\n", error);
|
||||
}
|
||||
|
||||
START_TEST(console)
|
||||
{
|
||||
|
@ -1187,4 +1222,5 @@ START_TEST(console)
|
|||
test_GetConsoleProcessList();
|
||||
test_OpenConsoleW();
|
||||
test_VerifyConsoleIoHandle();
|
||||
test_GetSetStdHandle();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue