Git Product home page Git Product logo

Comments (3)

rodrigocfd avatar rodrigocfd commented on June 4, 2024

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.

John-Nagle avatar John-Nagle commented on June 4, 2024

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.

rodrigocfd avatar rodrigocfd commented on June 4, 2024

Oops... my bad. It should work now.

from winsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.