Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Kim Christensen
@kichristensen
@retep998 thank you very much I will try that
Yonggang Luo
@lygstate
Why compier warm std/
|
= note: the lang item is first defined in crate std (which winapi depends on)
= note: first definition in 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.rlib
= note: second definition in the local crate (rulibc)
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)
whichwinapidepends on
How to import winapi and not fetch std?
Guy Tabak
@GuyTabak
Hi, I am trying to create a callback interface class, to communicate with BITS service through com api.
Is there any example of how to implement such an interface?
The interface I need to implement:
https://docs.microsoft.com/en-us/windows/win32/api/bits/nn-bits-ibackgroundcopycallback
There is an example for cpp, and I would need to implement it in rust.
echo!
@dotqurter
I'm trying to call winapi::um::memoryapi::VirtualAllocEx but it claims it can't find "memoryapi" in "um"
nicbn
@nicbn
@dotqurter You need to use winapi = { version = "...", features = ["memoryapi"] } in deps
@GuyTabak just create a repr(C) struct with the vtable of the interface as the first element
Then cast as needed
Aleksander Litynski
@AleksLitynski
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
It seems like in order to set multiple privileges, I would need multiple items in the array, per https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-token_privileges
R030t1
@R030t1

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``

@endeav0r
You posted that in 2018
endeav0r
@endeav0r
Lol.
R030t1
@R030t1
I'm pulling in winapi = {version = "*", features = ["minwinbase", "winuser"]} and just added minwinbase. This added "stuff" however the namespace winapi::minwinbase still does not exist. Are some of them not exported for some reason?
What is actually going on with the namespaces
endeav0r
@endeav0r
My guess is your passing something between different versions of winapi-rs, or you need to use winapi::um::minwinbase
R030t1
@R030t1
When I try to call CreateThread it is explicitly telling me I can't use winapi::um::minwinbase::SECURITY_ATTRIBUTE, I have to use the one in winapi::minwinbase.
But winapi::minwinbase doesn't exist for me.
R030t1
@R030t1
Sigh. I solved this before with a double cast, but I can not understand the namespacing.
For posterity, I use let mut attrib = ... then &mut attrib *mut _ as *mut _.
So if anyone knows it would be worth putting in documentation
herbyboi
@herbyboi

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.

Frank Buss
@Frank-Buss
I wrote a simple program to get the active window title, see below. But I'm not sure how to create and pass an empty string to be filled from a Windows function and then convert it to a Rust String. My program works, but is there an easier way to do it, maybe with OsStrExt? Also is the rest of the program ok? I'm relatively new to Rust itself.
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()
    );
}
And I noticed that "handle" has a different type than "WM_NULL". Is it right to cast like I did in my program?