Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
Adriano Grieb
hi there! it was probably asked a zillion times, but how do I get data back? I'm trying to get the returned value pvData and pcbData from a call to winapi::um::winreg::RegGetValueA... the function returns ERROR_SUCCESS if I set those both to std::ptr::null_mut(), so all other parameters are OK! I'm just stuck on how do declare those variables and converting then to and from... I'm new to rust!!!
Adriano Grieb
ok, did it! the solution is always simpler than we think....
let mut pvData = vec![0; 2];
let lstatus = unsafe { RegGetValueA(HKEY_CURRENT_USER,
                                        pvData.as_mut_ptr() as *mut c_void,
println!("SUCCESS {:?}", pvData[0]);
this key always has value 0 or 1, or does not exist, so I know a vec with size 2 is precisely what I need...
can you help me
D:/../cargo-cache/bin/cargo.exe build --color=always --all --all-targets
   Compiling proc-macro2 v1.0.19
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling winapi v0.3.9
   Compiling syn v1.0.34
   Compiling memchr v2.3.3
   Compiling log v0.4.11
   Compiling libc v0.2.73
   Compiling pin-project-internal v0.4.22
error: linking with `D:\dev\msys64\mingw32\bin\gcc.exe` failed: exit code: 1
  = note: "D:\\dev\\msys64\\mingw32\\bin\\gcc.exe" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-m64" "-nostartfiles" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\crt2.o" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373993d98adf607f.build_script_build.aqdalkxg-cgu.0.rcgu.o" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373"D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373993d98adf607f.build_script_build.aqdalkxg-cgu.8.rcgu.o" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373993d98adf607f.build_script_build.aqdalkxg-cgu.9.rcgu.o" "-o" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373993d98adf607f.exe" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\build\\winapi-x86_64-pc-windows-gnu-373993d98adf607f\\build_script_build-373993d98adf607f.3cs0v1emfhffbtuk.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "D:\\code\\jrtzcloud\\rust\\quotes-bak-task\\target\\debug\\deps" "-L" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,--start-group" "-Wl,-Bstatic" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libstd-67d47d305e6416cf.rlib" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_unwind-7a60e9aa38c75ecbcore-56e7371f88c71370.rlib" "-Wl,--end-group" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-8320c8f14264e1a8.rlib" "-Wl,-Bdynamic" "-ladvapi32" "-lws2_32" "-luserenv" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lmsvcrt" "-luser32" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lgcc" "-lmsvcrt" "-lkernel32" "D:\\rust-toolchain\\toolchains\\stable-x86_64-pc-windows-gnu\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
  = note: 

error: aborting due to previous error

error: could not compile `winapi-x86_64-pc-windows-gnu`.
what's this problem?
Could you help me, thanks
Peter Atashian
@marvinpan8 That issue is not specific to winapi. Since it appears you are using an external MinGW toolchain it is recommended you disable the bundled MinGW toolchain that Rust provides. It is currently a nightly only feature and you can enable it with the rust flag -Z link-self-contained=no.
Kim Christensen
Hi everyone, I have a quesiton. I'm looking into extending some of the DirectWrite API in winapi, and ran into an issue, I have no idea on how to solve. Taking a look at the DWRITE_COLOR_GLYPH_RUN1 struct, https://docs.microsoft.com/en-us/windows/win32/api/dwrite_3/ns-dwrite_3-dwrite_color_glyph_run1, shows that it uses inheritance. Is this even possible to support in winapi? If it is could someone point me in the right direction?
Peter Atashian
@kichristensen I know I've run into this in the past but I don't remember the exact solution I used.
@kichristensen Okay, I found an existing case. If you have struct FOO: BAR {in C, in Rust you would make the first field of FOO be parent: BAR.
Kim Christensen
@retep998 thank you very much I will try that
Yonggang Luo
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
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:
There is an example for cpp, and I would need to implement it in rust.
I'm trying to call winapi::um::memoryapi::VirtualAllocEx but it claims it can't find "memoryapi" in "um"
@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
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

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

You posted that in 2018
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
My guess is your passing something between different versions of winapi-rs, or you need to use winapi::um::minwinbase
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.
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

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
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])


fn main() {
        "active window title: {}",
And I noticed that "handle" has a different type than "WM_NULL". Is it right to cast like I did in my program?
hey everyone, i'm trying to use this crate to mute/unmute the audio on the current system
i know that i have to use something like GetDefaultAudioEndpoint and then call mute or unmute on that
but i can't quite seem t oget it working