diff --git a/crates/libs/core/src/imp/factory_cache.rs b/crates/libs/core/src/imp/factory_cache.rs index eb4b2dac0e..62085a1b73 100644 --- a/crates/libs/core/src/imp/factory_cache.rs +++ b/crates/libs/core/src/imp/factory_cache.rs @@ -16,6 +16,12 @@ impl FactoryCache { } } +impl Default for FactoryCache { + fn default() -> Self { + Self::new() + } +} + impl FactoryCache { pub fn call crate::Result>(&self, callback: F) -> crate::Result { loop { diff --git a/crates/libs/core/src/param.rs b/crates/libs/core/src/param.rs index cd16d473f2..5061d41c0b 100644 --- a/crates/libs/core/src/param.rs +++ b/crates/libs/core/src/param.rs @@ -91,3 +91,15 @@ impl IntoParam for &HSTRING { Param::Owned(PCWSTR(self.as_ptr())) } } + +impl IntoParam for PWSTR { + unsafe fn into_param(self) -> Param { + Param::Owned(PCWSTR(self.0)) + } +} + +impl IntoParam for PSTR { + unsafe fn into_param(self) -> Param { + Param::Owned(PCSTR(self.0)) + } +} diff --git a/crates/tests/string_param/Cargo.toml b/crates/tests/string_param/Cargo.toml index 87df5ff40a..929589de05 100644 --- a/crates/tests/string_param/Cargo.toml +++ b/crates/tests/string_param/Cargo.toml @@ -8,4 +8,5 @@ publish = false path = "../../libs/windows" features = [ "Win32_Foundation", + "Win32_UI_Shell", ] diff --git a/crates/tests/string_param/tests/pwstr.rs b/crates/tests/string_param/tests/pwstr.rs index 8d4ad40715..2510c9a889 100644 --- a/crates/tests/string_param/tests/pwstr.rs +++ b/crates/tests/string_param/tests/pwstr.rs @@ -1,7 +1,7 @@ -use windows::{core::*, Win32::Foundation::*}; +use windows::{core::*, Win32::Foundation::*, Win32::UI::Shell::*}; #[test] -fn test() { +fn error() { unsafe { SetLastError(ERROR_BUSY_DRIVE); @@ -15,3 +15,16 @@ fn test() { assert_eq!(GetLastError(), ERROR_BUSY_DRIVE); } } + +#[test] +fn convert() { + unsafe { + let pcwstr: PCWSTR = w!("https://github.com/microsoft"); + let pwstr = PWSTR(pcwstr.0 as _); + let pcstr: PCSTR = s!("https://github.com/microsoft"); + let pstr = PSTR(pcstr.0 as _); + + assert_eq!(0, UrlCompareW(pcwstr, pwstr, true)); + assert_eq!(0, UrlCompareA(pcstr, pstr, true)); + } +}