Hi!
I tried implementing a small "Hello World" gist using a Windows MessageBox.
Is this "good style"? I.e. is that a good basis to start building a Windows applications?
Thanks in advance for your insights!
Cheers,
Kosta
Hi!
I tried implementing a small "Hello World" gist using a Windows MessageBox.
Is this "good style"? I.e. is that a good basis to start building a Windows applications?
Thanks in advance for your insights!
Cheers,
Kosta
There's no need to use encoding
to do utf-8 <-> utf-16 conversions because OsStringExt
in std
already provides an encode_wide
method to convert to UTF-16.
I personally use something like this for working with wide strings.
trait ToWide {
fn to_wide(&self) -> Vec<u16>;
fn to_wide_null(&self) -> Vec<u16>;
}
impl<T> ToWide for T where T: AsRef<OsStr> {
fn to_wide(&self) -> Vec<u16> {
self.as_ref().encode_wide().collect()
}
fn to_wide_null(&self) -> Vec<u16> {
self.as_ref().encode_wide().chain(Some(0)).collect()
}
}
let s = "some string".to_wide_null();
SomeWinapiFunction(s.as_ptr());
Hi @retep998!
First of all, thanks for providing these awesome winapi bindings!
I figured that I was missing something when using encoding
.
Still, I don't understand your code... x
refers to self, right?
But where is encode_wide? I don't find it anywhere in the docs, even in nightly:
It's definitely not on OsStringExt (should I be worried that this is in std::os::unix::ffi?)
Do you mean the unstable encode_utf16?
Thanks in advance for your insights!
Cheers,
Kosta
The online docs are generated on Linux and don't show any of the Windows-specific parts. Try looking at the locally installed documentation.
Oh yeah, that was a typo, replace x
with self
.
The documentation online is for linux, so you'll need to use the offline docs that came bundled with your Windows Rust installation instead.
encode_wide
is part of std::os::windows::ffi::OsStrExt
and from_wide
is part of std::os::windows::ffi::OsStringExt
. These functions are definitely stable but they're also Windows specific.
I have a funny feeling when your question is same as mine :
issue on missing doc for windows platform:
https://github.com/rust-lang/rust/issues/24658
@retep998 Aaaaahhh, now OsStr starts to make some sense!
@bungcip Thanks for linking these issues! I commented on them.
I think we should really have some resource on how to start with Rust development on Windows, what the current state is, which PRs/issues to follow etc. It's inefficient to have this only on this forums/reddit and every developer asking for themselves.
Where should such a page be hosted? I'm not aware of a rust wiki...