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

Allow PWSTR/PSTR to be passed to PCWSTR/PCSTR parameters #2899

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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
6 changes: 6 additions & 0 deletions crates/libs/core/src/imp/factory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ impl<C, I> FactoryCache<C, I> {
}
}

impl<C, I> Default for FactoryCache<C, I> {
fn default() -> Self {
Self::new()
}
}

impl<C: crate::RuntimeName, I: Interface> FactoryCache<C, I> {
pub fn call<R, F: FnOnce(&I) -> crate::Result<R>>(&self, callback: F) -> crate::Result<R> {
loop {
Expand Down
12 changes: 12 additions & 0 deletions crates/libs/core/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ impl IntoParam<PCWSTR> for &HSTRING {
Param::Owned(PCWSTR(self.as_ptr()))
}
}

impl IntoParam<PCWSTR> for PWSTR {
unsafe fn into_param(self) -> Param<PCWSTR> {
Param::Owned(PCWSTR(self.0))
}
}

impl IntoParam<PCSTR> for PSTR {
unsafe fn into_param(self) -> Param<PCSTR> {
Param::Owned(PCSTR(self.0))
}
}
1 change: 1 addition & 0 deletions crates/tests/string_param/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ publish = false
path = "../../libs/windows"
features = [
"Win32_Foundation",
"Win32_UI_Shell",
]
17 changes: 15 additions & 2 deletions crates/tests/string_param/tests/pwstr.rs
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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));
}
}