Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to windows 0.39.0 #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ xml-rs = "0.8.4"
strum = { version = "0.22.0", features = ["derive"] }

[target.'cfg(target_env = "msvc")'.dependencies.windows]
version = "0.24.0"
version = "0.39.0"
features = [
"Win32_Foundation",
"Foundation_Collections",
Expand All @@ -29,7 +29,7 @@ features = [
]

[target.'cfg(target_env = "gnu")'.dependencies.windows]
version = "0.24.0"
version = "0.39.0"
features = [
"Win32_Foundation",
"Foundation_Collections",
Expand Down
10 changes: 5 additions & 5 deletions examples/without_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use windows::{
UI::Notifications::ToastNotificationManager,
};

pub use windows::runtime::{
pub use windows::core::{
Error,
HSTRING,
};
Expand All @@ -26,10 +26,10 @@ fn main() {
std::thread::sleep(std::time::Duration::from_millis(10));
}

fn do_toast() -> windows::runtime::Result<()> {
fn do_toast() -> windows::core::Result<()> {
let toast_xml = XmlDocument::new()?;

toast_xml.LoadXml(HSTRING::from(
toast_xml.LoadXml(&HSTRING::from(
format!(r#"<toast duration="long">
<visual>
<binding template="ToastGeneric">
Expand All @@ -48,10 +48,10 @@ fn do_toast() -> windows::runtime::Result<()> {
))).expect("the xml is malformed");

// Create the toast and attach event listeners
let toast_template = ToastNotification::CreateToastNotification(toast_xml)?;
let toast_template = ToastNotification::CreateToastNotification(&toast_xml)?;

// If you have a valid app id, (ie installed using wix) then use it here.
let toast_notifier = ToastNotificationManager::CreateToastNotifierWithId(HSTRING::from(
let toast_notifier = ToastNotificationManager::CreateToastNotifierWithId(&HSTRING::from(
"{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe",
))?;

Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::path::Path;
use xml::escape::escape_str_attribute;
mod windows_check;

pub use windows::runtime::{Error, HSTRING, Result};
pub use windows::core::{Error, HSTRING, Result};
pub use windows::UI::Notifications::ToastNotification;

pub struct Toast {
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Toast {
self
}

fn create_template(&self) -> windows::runtime::Result<ToastNotification> {
fn create_template(&self) -> windows::core::Result<ToastNotification> {
//using this to get an instance of XmlDocument
let toast_xml = XmlDocument::new()?;

Expand All @@ -300,7 +300,7 @@ impl Toast {
}
};

toast_xml.LoadXml(HSTRING::from(format!(
toast_xml.LoadXml(&HSTRING::from(format!(
"<toast {} {}>
<visual>
<binding template=\"{}\">
Expand All @@ -321,14 +321,14 @@ impl Toast {
)))?;

// Create the toast
ToastNotification::CreateToastNotification(toast_xml)
ToastNotification::CreateToastNotification(&toast_xml)
}

/// Display the toast on the screen
pub fn show(&self) -> windows::runtime::Result<()> {
pub fn show(&self) -> windows::core::Result<()> {
let toast_template = self.create_template()?;

let toast_notifier = ToastNotificationManager::CreateToastNotifierWithId(HSTRING::from(&self.app_id))?;
let toast_notifier = ToastNotificationManager::CreateToastNotifierWithId(&HSTRING::from(&self.app_id))?;

// Show the toast.
let result = toast_notifier.Show(&toast_template);
Expand Down
8 changes: 7 additions & 1 deletion src/windows_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ mod internal {
// but we know it's in ntdll which will always be present at runtime.
#[cfg(target_env = "gnu")]
mod internal {
use windows::core::PCSTR;
use windows::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};

#[allow(non_upper_case_globals)]
static mut CacheRtlGetNtVersionNumbers: Option<unsafe extern "system" fn() -> isize> = None;

#[allow(non_snake_case)]
pub unsafe fn RtlGetNtVersionNumbers(major: *mut u32, minor: *mut u32, build: *mut u32) {
const NTDLL: PCSTR = PCSTR::from_raw("ntdll.dll".as_bytes().as_ptr());
const RTL_GET_VERSION_NUMBERS: PCSTR = PCSTR::from_raw("RtlGetNtVersionNumbers".as_bytes().as_ptr());

if CacheRtlGetNtVersionNumbers.is_none() {
CacheRtlGetNtVersionNumbers = GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlGetNtVersionNumbers");
if let Ok(handle) = GetModuleHandleA(NTDLL) {
CacheRtlGetNtVersionNumbers = GetProcAddress(handle, RTL_GET_VERSION_NUMBERS);
}
}

if let Some(RtlGetNtVersionNumbers_FUNCTION) = CacheRtlGetNtVersionNumbers {
Expand Down