Skip to content

Commit 65d63ca

Browse files
authored
Rollup merge of #103637 - ChrisDenton:stdio-uwp, r=thomcc
Use stdio in UWP apps Fixes #103233 This has been supported since Windows 10.0.16299. See https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-apis#apis-from-api-ms-win-core-console-l1-1-0dll
2 parents 69e7055 + 5857c30 commit 65d63ca

File tree

3 files changed

+28
-120
lines changed

3 files changed

+28
-120
lines changed

library/std/src/sys/windows/c.rs

+27-30
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
5656
pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
5757
pub type LPSTARTUPINFO = *mut STARTUPINFO;
5858
pub type LPVOID = *mut c_void;
59+
pub type LPCVOID = *const c_void;
5960
pub type LPWCH = *mut WCHAR;
6061
pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
6162
pub type LPWSADATA = *mut WSADATA;
@@ -773,6 +774,16 @@ pub struct timeval {
773774
pub tv_usec: c_long,
774775
}
775776

777+
#[repr(C)]
778+
#[derive(Copy, Clone)]
779+
pub struct CONSOLE_READCONSOLE_CONTROL {
780+
pub nLength: ULONG,
781+
pub nInitialChars: ULONG,
782+
pub dwCtrlWakeupMask: ULONG,
783+
pub dwControlKeyState: ULONG,
784+
}
785+
pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
786+
776787
// Desktop specific functions & types
777788
cfg_if::cfg_if! {
778789
if #[cfg(not(target_vendor = "uwp"))] {
@@ -801,17 +812,6 @@ if #[cfg(not(target_vendor = "uwp"))] {
801812
pub type PVECTORED_EXCEPTION_HANDLER =
802813
extern "system" fn(ExceptionInfo: *mut EXCEPTION_POINTERS) -> LONG;
803814

804-
#[repr(C)]
805-
#[derive(Copy, Clone)]
806-
pub struct CONSOLE_READCONSOLE_CONTROL {
807-
pub nLength: ULONG,
808-
pub nInitialChars: ULONG,
809-
pub dwCtrlWakeupMask: ULONG,
810-
pub dwControlKeyState: ULONG,
811-
}
812-
813-
pub type PCONSOLE_READCONSOLE_CONTROL = *mut CONSOLE_READCONSOLE_CONTROL;
814-
815815
#[repr(C)]
816816
pub struct BY_HANDLE_FILE_INFORMATION {
817817
pub dwFileAttributes: DWORD,
@@ -827,7 +827,6 @@ if #[cfg(not(target_vendor = "uwp"))] {
827827
}
828828

829829
pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
830-
pub type LPCVOID = *const c_void;
831830

832831
pub const HANDLE_FLAG_INHERIT: DWORD = 0x00000001;
833832

@@ -855,24 +854,6 @@ if #[cfg(not(target_vendor = "uwp"))] {
855854

856855
#[link(name = "kernel32")]
857856
extern "system" {
858-
// Functions forbidden when targeting UWP
859-
pub fn ReadConsoleW(
860-
hConsoleInput: HANDLE,
861-
lpBuffer: LPVOID,
862-
nNumberOfCharsToRead: DWORD,
863-
lpNumberOfCharsRead: LPDWORD,
864-
pInputControl: PCONSOLE_READCONSOLE_CONTROL,
865-
) -> BOOL;
866-
867-
pub fn WriteConsoleW(
868-
hConsoleOutput: HANDLE,
869-
lpBuffer: LPCVOID,
870-
nNumberOfCharsToWrite: DWORD,
871-
lpNumberOfCharsWritten: LPDWORD,
872-
lpReserved: LPVOID,
873-
) -> BOOL;
874-
875-
pub fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL;
876857
// Allowed but unused by UWP
877858
pub fn GetFileInformationByHandle(
878859
hFile: HANDLE,
@@ -914,6 +895,22 @@ if #[cfg(target_vendor = "uwp")] {
914895
extern "system" {
915896
pub fn GetCurrentProcessId() -> DWORD;
916897

898+
pub fn ReadConsoleW(
899+
hConsoleInput: HANDLE,
900+
lpBuffer: LPVOID,
901+
nNumberOfCharsToRead: DWORD,
902+
lpNumberOfCharsRead: LPDWORD,
903+
pInputControl: PCONSOLE_READCONSOLE_CONTROL,
904+
) -> BOOL;
905+
pub fn WriteConsoleW(
906+
hConsoleOutput: HANDLE,
907+
lpBuffer: LPCVOID,
908+
nNumberOfCharsToWrite: DWORD,
909+
lpNumberOfCharsWritten: LPDWORD,
910+
lpReserved: LPVOID,
911+
) -> BOOL;
912+
pub fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL;
913+
917914
pub fn GetSystemDirectoryW(lpBuffer: LPWSTR, uSize: UINT) -> UINT;
918915
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
919916
pub fn SetFileAttributesW(lpFileName: LPCWSTR, dwFileAttributes: DWORD) -> BOOL;

library/std/src/sys/windows/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ pub mod path;
2929
pub mod pipe;
3030
pub mod process;
3131
pub mod rand;
32+
pub mod stdio;
3233
pub mod thread;
3334
pub mod thread_local_dtor;
3435
pub mod thread_local_key;
3536
pub mod thread_parker;
3637
pub mod time;
3738
cfg_if::cfg_if! {
3839
if #[cfg(not(target_vendor = "uwp"))] {
39-
pub mod stdio;
4040
pub mod stack_overflow;
4141
} else {
42-
pub mod stdio_uwp;
4342
pub mod stack_overflow_uwp;
44-
pub use self::stdio_uwp as stdio;
4543
pub use self::stack_overflow_uwp as stack_overflow;
4644
}
4745
}

library/std/src/sys/windows/stdio_uwp.rs

-87
This file was deleted.

0 commit comments

Comments
 (0)