Comments (3)
A new version of the crate is coming out probably on April, but note that you don't need to wait. You can clone the repo locally or specify the dependency straight from GitHub.
Let me know if this worked for you.
from winsafe.
That's great! I got it working. Found a bug, though.
This works:
use anyhow::{Error};
/// Implementation for Windows
#[cfg(target_os="windows")]
pub fn get_id0() -> Result<String, Error> {
const CDRIVE: &str = "C:\\"; // name to ask for
let mut disk_serial_number: u32 = 0; // destination for serial number
let mut name = String::new(); // destination for name
let mut file_system_name = String::new(); // destination for file system name
winsafe::GetVolumeInformation(
Some(CDRIVE),
Some(&mut name),
Some(&mut disk_serial_number),
None,
None,
Some(&mut file_system_name))?;
println!("Disk serial number: {}", disk_serial_number); // ***TEMP***
println!("File system name: {}", file_system_name); // ***TEMP***
Ok(format!("{:032x}", md5::compute(disk_serial_number.to_le_bytes())))
}
fn main() {
println!("Hello, world from id0={}", get_id0().unwrap());
}
But I had to provide empty strings for name
and file_system_name
, which are optional values. If I use None there, I get
wine winutiltest.exe
thread 'main' panicked at 'Trying to use an unallocated WString buffer.', /home/john/.cargo/git/checkouts/winsafe-cbd1b977182a662f/e80fcd8/src/kernel/utilities/w_string.rs:186:20
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src/panicking.rs:116:14
2: winsafe::kernel::utilities::w_string::WString::as_mut_ptr::{{closure}}
at /home/john/.cargo/git/checkouts/winsafe-cbd1b977182a662f/e80fcd8/src/kernel/utilities/w_string.rs:186:8
3: core::option::Option<T>::map_or_else
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\option.rs:977:21
4: winsafe::kernel::utilities::w_string::WString::as_mut_ptr
at /home/john/.cargo/git/checkouts/winsafe-cbd1b977182a662f/e80fcd8/src/kernel/utilities/w_string.rs:184:3
5: winsafe::kernel::funcs::GetVolumeInformation
at /home/john/.cargo/git/checkouts/winsafe-cbd1b977182a662f/e80fcd8/src/kernel/funcs.rs:439:5
6: winutiltest::get_id0
at /home/john/projects/rustcode/winutiltest/src/main.rs:10:5
7: winutiltest::main
at /home/john/projects/rustcode/winutiltest/src/main.rs:23:42
8: core::ops::function::FnOnce::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\core\src\ops\function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
This is happening in winsafe::kernel::funcs::GetVolumeInformation
`name_buf.0.as_mut_ptr(),`
and at
`sys_name_buf.0.as_mut_ptr(),`
so, apparently applying as_mut_ptr
() to a null pointer is not allowed.
from winsafe.
Oops... my bad. It should work now.
from winsafe.
Related Issues (20)
- validate_retrieved_reg_val always fails
- [Question] - Calling windows APIs twice best practice HOT 3
- RegQueryValueEx returning TRANSACTION_REQUEST_NOT_VALID for valid data HOT 6
- nm_custom_draw should provide a mutable reference? HOT 6
- How do you envision WM_USER being used? HOT 1
- `WC::NoValue`? HOT 1
- Wrong GetAsyncKeyState return type. HOT 4
- SetLayeredWindowAttributes HOT 3
- GetTokenInformation missing HOT 2
- Panic when add empty strings in listview HOT 2
- How to display rich text such as superscript/subscript? HOT 3
- [Feature Request] Message only window support HOT 3
- [Feature Request] Implement Ord, PartialOrd, Eq and PartialEq for WString
- Public access ot LocalFreeGuard::new or LocalFree HOT 2
- [BUG?QUESTION?]SendInput example not working HOT 1
- [Question] How can I set the pszText into NMLVDISPINFO correctly when handling lvn_get_disp_info event? HOT 19
- [Question] Using MutFn as WinApi callback
- WString pointers cause issues on stack for certain API calls HOT 5
- Build fails for the i686-pc-windows-(msvc/gnu) targets HOT 8
- winsvc.h HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winsafe.