Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
Peter Atashian
and unfortunately tools like bindgen don't work very well
Brian Merchant
what's the preferred way to pass a path to a winapi wrapper?
i'm finding that there's no easy way to go from OsStr to a const * _?
Peter Atashian
@bzm3r OsStrExt::encode_wide().chain(once(0)).collect() to get you a Vec<u16>. You can then call .as_ptr() on it to get a pointer to pass to winapi.
@bzm3r As for your ID3D10Blob question, you would call the GetBufferPointer and GetBufferSize methods to get the pointer and size, and pass them to std::slice::from_raw_parts to get a &[T].
If the blob is a unicode string you would get a &[u16] and pass it to OsStringExt::from_wide()
Barret Rennie
Howdy. Is there an expected release date for the 0.38? I'd like to use the DISK_PERFORMANCE struct that was added recently.
Peter Atashian
@brennie I am currently in the process of verifying I did not break backwards compatibility before I publish a new version.
Barret Rennie
How exactly do I go about using the struct CHAR_INFO_Char? I'm trying to use it in conjunction with the struct CHAR_INFO but I'm not sure how to go about populating its private field.
actually, scratch that. I think I found an example I can work off of
Peter Atashian
@MarkAnthonyM Initialize CHAR_INFO with zeroed() or Default and then use the methods to access the union variant and assign the value you want
it'll be better in winapi 0.4 which will use actual unions
Ah, I was just looking over the function of zeroed() in the rust docs when you sent this message. Many thanks!
Hilmar Gústafsson
Can anyone tell me why this code is failing on CoCreateInstance with a class not found error? https://github.com/LiHRaM/egpu-rs/blob/master/src/main.rs
the HRESULT specifically is: 0x80040154
Dan Kyung
How do I use ReadFile? More specifically, I'm wondering what types to pass into lpBuffer. let mut buffer_read: LPVOID = std::ptr::null_mut(); is the closest I got and that remains null.
Dan Kyung
let mut buffer_read = vec![0; 5]; worked ^
Mathieu Tarral
hi !
small issue here, I can't figure out how to import tlhelp32
error[E0432]: unresolved import `winapi::um::tlhelp32`
import winapi::um works though
ok, i have to enable a feature to gain access to tlhelp32
lihram Hey, does anyone know if winapi-rs has support for toast notifications, or how I might access them?
lihram This is the relevant windows documentation for C++
I am trying to use UIAutomation in my project.
I've found out only https://lib.rs/install/uiautomationcore-sys
But there is no documentation how to use it. Maybe anybody knows or there is better way? Thanks!

Hello, I'm struggling with following problem:
I have a BITMAP declared like this

            let mut bmp: BITMAP = mem::uninitialized();

then I'm trying to call a GetObject

                bitmap as HANDLE,
                mem::size_of::<BITMAP>() as i32,
                &mut bmp as * LPVOID,

And I'm getting

error[E0606]: casting `&mut winapi::um::wingdi::BITMAP` as `*mut std::ffi::c_void` is invalid
   --> src\main.rs:118:17
118 |                 &mut bmp as LPVOID,
    |                 ^^^^^^^^^^^^^^^^^^
I've tried different combinations of types in cast expression but still cannot find a correct one
Peter Atashian
@rucoder_gitlab &mut bmp as *mut BITMAP as LPVOID
@rucoder_gitlab Alternatively <*mut _>::cast(&mut bmp)
Thanks. I've figured out it already but the second alternative is unknown to me. I'm still learning Rust :)
as I understand the rule here is : "cast reference to the pointer of the same type and then reinterpret pointer with second 'as'"
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?