pub struct HSTD(/* private fields */);
kernel
only.Expand description
Handle to a
standard device.
Originally just a HANDLE
.
Implementations§
Source§impl HSTD
impl HSTD
Sourcepub const unsafe fn from_ptr(p: *mut c_void) -> Self
pub const unsafe fn from_ptr(p: *mut c_void) -> Self
Constructs a new handle object by wrapping a pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.
Sourcepub const unsafe fn raw_copy(&self) -> Self
pub const unsafe fn raw_copy(&self) -> Self
Returns a raw copy of the underlying handle pointer.
§Safety
As the name implies, raw_copy
returns a raw copy of the
handle, so closing one of the copies won’t close the others.
This means a handle can be used after it has been closed, what
can lead to errors and undefined behavior. Even worse: sometimes
Windows reuses handle values, so you can call a method on a
completely different handle type, what can be catastrophic.
However, in some cases the Windows API demands a copy of the
handle – raw_copy
is an escape hatch to fill this gap.
Sourcepub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
pub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
Returns a mutable reference to the underlying raw pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
Sourcepub const fn ptr(&self) -> *mut c_void
pub const fn ptr(&self) -> *mut c_void
Returns the underlying raw pointer.
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
This method can be used as an escape hatch to interoperate with other libraries.
Source§impl HSTD
impl HSTD
Sourcepub fn FlushConsoleInputBuffer(&self) -> SysResult<()>
pub fn FlushConsoleInputBuffer(&self) -> SysResult<()>
FlushConsoleInputBuffer
function.
Sourcepub fn GetConsoleMode(&self) -> SysResult<CONSOLE>
pub fn GetConsoleMode(&self) -> SysResult<CONSOLE>
GetConsoleMode
function.
Sourcepub fn GetStdHandle(std_handle: STD_HANDLE) -> SysResult<CloseHandleGuard<HSTD>>
pub fn GetStdHandle(std_handle: STD_HANDLE) -> SysResult<CloseHandleGuard<HSTD>>
GetStdHandle
function.
Sourcepub fn ReadConsole(
&self,
buffer: &mut WString,
input_control: Option<&CONSOLE_READCONSOLE_CONTROL>,
) -> SysResult<u32>
pub fn ReadConsole( &self, buffer: &mut WString, input_control: Option<&CONSOLE_READCONSOLE_CONTROL>, ) -> SysResult<u32>
ReadConsole
function.
Returns the number of chars actually written.
§Examples
use winsafe::{self as w, prelude::*, co};
let hstd = w::HSTD::GetStdHandle(co::STD_HANDLE::INPUT)?;
let mut buffer = w::WString::new_alloc_buf(2048);
hstd.ReadConsole(&mut buffer, None)?;
let text = buffer.to_string();
Sourcepub fn SetConsoleMode(&self, mode: CONSOLE) -> SysResult<()>
pub fn SetConsoleMode(&self, mode: CONSOLE) -> SysResult<()>
SetConsoleMode
function.
Sourcepub fn WriteConsole(&self, text: &str) -> SysResult<u32>
pub fn WriteConsole(&self, text: &str) -> SysResult<u32>
WriteConsole
function.
Returns the number of chars actually written.