Repository navigation
Closed
Description
I have just started learning Rust and was playing around.
I found out that SendInput takes only one INPUT but according to the Microsoft Windows API documentation it should take an array of INPUTs.
I think this is a bug but please let me know if I'm wrong and if so please tell me how to make it work!
This code compiles:
use bindings::{
Windows::Win32::UI::KeyboardAndMouseInput::{INPUT, INPUT_0, INPUT_TYPE, KEYBDINPUT, KEYBD_EVENT_FLAGS, SendInput},
Windows::Win32::UI::WindowsAndMessaging::GetMessageExtraInfo,
};
use std::mem::size_of;
fn main(){
const CBSIZE: i32 = size_of::<INPUT>() as i32;
for i in 1..10 {
unsafe {
let extra_info = GetMessageExtraInfo();
let extra_info = extra_info.0.unsigned_abs();
let cinputs: u32 = 1;
let mut pinputs = INPUT {
r#type: INPUT_TYPE {0: 1},
Anonymous: INPUT_0 {
ki: KEYBDINPUT {
wVk: 0x41,
wScan: 1,
dwFlags: KEYBD_EVENT_FLAGS(0),
time: 0,
dwExtraInfo: extra_info,
}
}
};
let res = SendInput(cinputs, &mut pinputs, CBSIZE);
println!("{}. {}", i, res);
}
}
}
But this code dosn't:
use bindings::{
Windows::Win32::UI::KeyboardAndMouseInput::{INPUT, INPUT_0, INPUT_TYPE, KEYBDINPUT, KEYBD_EVENT_FLAGS, SendInput},
Windows::Win32::UI::WindowsAndMessaging::GetMessageExtraInfo,
};
use std::mem::size_of;
fn main(){
const CBSIZE: i32 = size_of::<INPUT>() as i32;
for i in 1..10 {
unsafe {
let extra_info = GetMessageExtraInfo();
let extra_info = extra_info.0.unsigned_abs();
let cinputs: u32 = 1;
let mut pinputs = [
INPUT {
r#type: INPUT_TYPE {0: 1},
Anonymous: INPUT_0 {
ki: KEYBDINPUT {
wVk: 0x41,
wScan: 1,
dwFlags: KEYBD_EVENT_FLAGS(0),
time: 0,
dwExtraInfo: extra_info,
}
}
},
];
let res = SendInput(cinputs, &mut pinputs, CBSIZE);
println!("{}. {}", i, res);
}
}
}
Error:
error[E0308]: mismatched types
--> src\main.rs:29:42
|
29 | let res = SendInput(cinputs, &mut pinputs, CBSIZE);
| ^^^^^^^^^^^^ expected struct `INPUT`, found array of 1 element
|
= note: expected raw pointer `*mut INPUT`
found mutable reference `&mut [INPUT; 1]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `wintest`
To learn more, run the command again with --verbose.
You can find the working code here
Metadata
Metadata
Assignees
Labels
No labels
Activity
riverar commentedon Jul 12, 2021
Hey CrumblyLiquid (@CrumblyLiquid) (love the name). Doesn't look like the crate handles NativeArrayInfo attributes yet, see also #790.
cc: Kenny Kerr (@kennykerr)
kennykerr commentedon Jul 12, 2021
Yep, there are a few array-related issues currently open. There is a whole class of array parameter handling I still need to get to.
kennykerr commentedon Feb 23, 2022
Sorry for the delay, #1562 adds support for Win32 array parameters and fixes this issue.