struct FOO: BAR {
in C, in Rust you would make the first field of FOO
be parent: BAR
.
std
(which winapi
depends on)std
loaded from \?\C:\Users\lygstate.rustup\toolchains\nightly-2020-10-01-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\std-d2161836abc64f12.dll, \?\C:\Users\lygstate.rustup\toolchains\nightly-2020-10-01-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-d2161836abc64f12.rlibrulibc
)
error[E0152]: found duplicate lang item `panic_impl`
--> src\lib.rs:89:1
|
89 | pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `std` (which `winapi` depends on)
which
winapidepends on
repr(C)
struct with the vtable of the interface as the first element
I’m just getting started with winapi-rs. Any idea why I can’t
use winapi::um::minwinbase::SECURITY_ATTRIBUTES
:error[E0432]: unresolved import `winapi::um::minwinbase` --> src/main.rs:4:17 | 4 | use winapi::um::minwinbase::SECURITY_ATTRIBUTES; | ^^^^^^^^^^ Could not find `minwinbase` in `um`
I found this in Google search. I have a similar problem, how did you fix it? I get expected struct `winapi::minwinbase::SECURITY_ATTRIBUTES`, found struct `winapi::um::minwinbase::SECURITY_ATTRIBUTES``
winapi::minwinbase
doesn't exist for me.
Does anyone know why this array is constrained to only one item? https://docs.rs/winapi/0.3.9/winapi/um/winnt/struct.TOKEN_PRIVILEGES.html#structfield.Privileges
I'm also curious about how to read multiple entries and evaluate the size of such struct when used as a buffer.
use std::io::{Error, ErrorKind};
use winapi;
use winapi::shared::minwindef::*;
use winapi::shared::windef::*;
fn get_active_window_title() -> Result<String, Error> {
let handle = unsafe { winapi::um::winuser::GetForegroundWindow() };
if handle as UINT == winapi::um::winuser::WM_NULL {
return Err(Error::new(ErrorKind::Other, "GetForegroundWindow failed"));
}
let title = unsafe {
const MAX_TITLE_LENGTH: usize = 255;
let mut v: [u16; MAX_TITLE_LENGTH] = [0; MAX_TITLE_LENGTH];
let read_len =
winapi::um::winuser::GetWindowTextW(handle as HWND, v.as_mut_ptr(), MAX_TITLE_LENGTH as i32);
String::from_utf16_lossy(&v[0..read_len as usize])
};
Ok(title)
}
fn main() {
println!(
"active window title: {}",
get_active_window_title().unwrap()
);
}