diff options
| author | Fuwn <[email protected]> | 2022-01-04 15:31:37 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-04 15:31:37 -0800 |
| commit | 651d0f46df0acb38b9d157dad234ae2cada79a90 (patch) | |
| tree | d2079f9f68f7ef89e7498d07eb306f17040422c8 /crates/user/io_controls/src/main.rs | |
| parent | chore(crates): migrate to edition 2021 (diff) | |
| download | driver-651d0f46df0acb38b9d157dad234ae2cada79a90.tar.xz driver-651d0f46df0acb38b9d157dad234ae2cada79a90.zip | |
feat(crates): new userspace examples
Thanks, StephanvanSchaik.
Diffstat (limited to 'crates/user/io_controls/src/main.rs')
| -rw-r--r-- | crates/user/io_controls/src/main.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/user/io_controls/src/main.rs b/crates/user/io_controls/src/main.rs new file mode 100644 index 0000000..1c5e73c --- /dev/null +++ b/crates/user/io_controls/src/main.rs @@ -0,0 +1,41 @@ +use std::os::windows::io::AsRawHandle; + +use winioctl::{ioctl_none, ioctl_read, ioctl_write, DeviceType, Error}; + +const IOCTL_PRINT_VALUE: u32 = 0x800; +const IOCTL_READ_VALUE: u32 = 0x801; +const IOCTL_WRITE_VALUE: u32 = 0x802; + +ioctl_none!(ioctl_print_value, DeviceType::Unknown, IOCTL_PRINT_VALUE); +ioctl_read!(ioctl_read_value, DeviceType::Unknown, IOCTL_READ_VALUE, i32); +ioctl_write!( + ioctl_write_value, + DeviceType::Unknown, + IOCTL_WRITE_VALUE, + i32 +); + +fn main() -> Result<(), Error> { + let file = std::fs::OpenOptions::new() + .read(true) + .write(true) + .create(false) + .open("\\??\\Example")?; + let mut value = 0; + + unsafe { + ioctl_read_value(file.as_raw_handle(), &mut value)?; + } + + value += 1; + + unsafe { + ioctl_write_value(file.as_raw_handle(), &value)?; + } + + unsafe { + ioctl_print_value(file.as_raw_handle())?; + } + + Ok(()) +} |