Trait winsafe::prelude::version_Hversioninfo

source ·
pub trait version_Hversioninfo: Handle {
    // Provided methods
    fn GetFileVersionInfo(file_name: &str) -> SysResult<VersionInfoGuard> { ... }
    fn GetFileVersionInfoSize(file_name: &str) -> SysResult<u32> { ... }
    fn langs_and_cps(&self) -> SysResult<&[(LANGID, CP)]> { ... }
    unsafe fn VarQueryValue<T>(
        &self,
        sub_block: &str
    ) -> SysResult<(*const T, u32)> { ... }
    fn str_val(
        &self,
        lang_id: LANGID,
        code_page: CP,
        name: &str
    ) -> SysResult<String> { ... }
    fn version_info(&self) -> SysResult<&VS_FIXEDFILEINFO> { ... }
}
Available on crate features kernel and version only.
Expand description

This trait is enabled with the version feature, and provides methods for HVERSIONINFO.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Provided Methods§

source

fn GetFileVersionInfo(file_name: &str) -> SysResult<VersionInfoGuard>

GetFileVersionInfo function.

The returned buffer will be automatically allocated with HVERSIONINFO::GetFileVersionInfoSize.

source

fn GetFileVersionInfoSize(file_name: &str) -> SysResult<u32>

GetFileVersionInfoSize function.

You don’t need to call this function directly, because HVERSIONINFO::GetFileVersionInfo already calls it.

source

fn langs_and_cps(&self) -> SysResult<&[(LANGID, CP)]>

Calls HVERSIONINFO::VarQueryValue to retrieve a reference to a slice with all languages and code pages.

§Examples

Listing all pairs of language and code page:

use winsafe::{self as w, prelude::*};

let exe_name = w::HINSTANCE::NULL.GetModuleFileName()?;
let hversion = w::HVERSIONINFO::GetFileVersionInfo(&exe_name)?;

for (lang, cp) in hversion.langs_and_cps()?.iter() {
    println!("{} {}", lang, cp);
}
source

unsafe fn VarQueryValue<T>(&self, sub_block: &str) -> SysResult<(*const T, u32)>

VarQueryValue function.

§Safety

The returned pointer and size vary according to lpSubBlock. If you set it wrong, you’re likely to cause a buffer overrun.

This function is rather tricky, consider using the high-level methods:

§Examples

Reading version information from resource:

use winsafe::{self as w, prelude::*};

let exe_name = w::HINSTANCE::NULL.GetModuleFileName()?;
let hversion = w::HVERSIONINFO::GetFileVersionInfo(&exe_name)?;

let (pvsf, sz_data) = unsafe {
    hversion.VarQueryValue::<w::VS_FIXEDFILEINFO>("\\")?
};

let ver = unsafe { &*pvsf }.dwFileVersion();
println!("Version {}.{}.{}.{}",
    ver[0], ver[1], ver[2], ver[3]);
source

fn str_val( &self, lang_id: LANGID, code_page: CP, name: &str ) -> SysResult<String>

Calls HVERSIONINFO::VarQueryValue to retrieve a string value.

Common value names are:

  • Comments
  • CompanyName
  • FileDescription
  • FileVersion
  • InternalName
  • LegalCopyright
  • LegalTrademarks
  • OriginalFilename
  • ProductName
  • ProductVersion
  • PrivateBuild
  • SpecialBuild
§Examples

Reading product name and legal copyright from resource:

use winsafe::{self as w, prelude::*};

let exe_name = w::HINSTANCE::NULL.GetModuleFileName()?;
let hversion = w::HVERSIONINFO::GetFileVersionInfo(&exe_name)?;

let (lang0, cp0) = hversion.langs_and_cps()?[0]; // first language and code page

println!(
    "{}\n{}",
    hversion.str_val(lang0, cp0, "ProductName")?,
    hversion.str_val(lang0, cp0, "LegalCopyright")?,
);
source

fn version_info(&self) -> SysResult<&VS_FIXEDFILEINFO>

Calls HVERSIONINFO::VarQueryValue to retrieve a reference to the fixed version block, if any.

Object Safety§

This trait is not object safe.

Implementors§