Skip to content

Commit

Permalink
Allow PWSTR/PSTR to be passed to PCWSTR/PCSTR parameters (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Feb 28, 2024
1 parent 5d06199 commit f3aa338
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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));
}
}

0 comments on commit f3aa338

Please sign in to comment.