-
Notifications
You must be signed in to change notification settings - Fork 524
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
Using BSTR
from a borrowed pointer
#3230
Comments
If you need an owned copy of a |
|
The code you've shown reads like you're looking for As far as functionality goes, what you're asking for is |
HSTRING should be that string type. If its not let me know. 😊 |
The string type I'm looking for is like However, I should dedicate a separate issue to this instead of hijacking this one. |
You may want to consider HStringBuilder. |
Hi @kennykerr - WDYT about having a Sounds to me like this should be safe (and useful) 😄 |
Since you want a If that is not something you want to do you could also |
@tim-weis What I'm asking is if it makes sense that For example, if I did this Your other suggestions don't really apply for my usecase. |
I think there's a larger issue here around the usability/ergonomics of |
Related: #2983 |
If you think that transmuting applies, then the other suggestion applies just as well. Constructing a slice manually merely avoids relying on windows-rs/crates/libs/strings/src/bstr.rs Lines 30 to 33 in 9f5ec21
And this this windows-rs/crates/libs/strings/src/bstr.rs Lines 21 to 28 in 9f5ec21
Either approach works, just as wrapping the This is a workaround until more complete variant support arrives. Footnotes
|
Taking a step back, is there an option to use |
Yes you are right @kennykerr, I still need Thanks! |
Suggestion
Hi,
Recently I wanted to use
windows_strings::BSTR
, but didn't have ownership of the original pointer.Is there a way to have something like
BSTR::from_raw_borrowed(*const u16) -> &BSTR
?Background
While updating the
wmi-rs
crate towindows
version 0.58 (PR), there was a need to change this code:Since
bstrVal
is*const u16
.The result is something like this:
(Which I think is right, since the
VARIANT
's data is owned by someone else)This would have been more ergonomic and less error prune if where was an option to construct a
&BSTR
from the raw pointer.Thanks for the awesome work!
The text was updated successfully, but these errors were encountered: