## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
Dan Kyung
@dank
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
@dank
let mut buffer_read = vec![0; 5]; worked ^
Mathieu Tarral
@Wenzel
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
matrixbot
@matrixbot
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++
matrixbot
@matrixbot
Lazy-256
@Lazy-256
Hi,
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!
Michael
@rucoder_gitlab

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

            GetObjectW(
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
@retep998
@rucoder_gitlab &mut bmp as *mut BITMAP as LPVOID
@rucoder_gitlab Alternatively <*mut _>::cast(&mut bmp)
Michael
@rucoder_gitlab
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'"
@griebd
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!!!
@griebd
ok, did it! the solution is always simpler than we think....
let mut pvData = vec![0; 2];
let lstatus = unsafe { RegGetValueA(HKEY_CURRENT_USER,
hkey.as_ptr(),
lpSubKey.as_ptr(),
RRF_RT_REG_DWORD,
std::ptr::null_mut(),
pvData.as_mut_ptr() as *mut c_void,
std::ptr::null_mut()
)};
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...
MarvinPan
@marvinpan8
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:

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
@retep998
@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
@kichristensen
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
@retep998
@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
@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.