Em qua, 1 de jul de 2015 às 02:36, Greg Jung <[email protected]> escreveu:
> In my programming instead of "multibytetowide" conversion preparing for a
> windows API inside #ifdef UNICODE blocks, I just call the ANSI mode of
> the function with ascii c-strings
> passed in, and let microsoft perform the A->W conversions. When does this
> simpler approach break?
>
> - Only use Win32 functions that accept widechars (LPWSTR), never those
> which accept LPTSTR or LPSTR. Pass parameters this way:
>
> ::SetWindowTextW(widen(someStdString or "string litteral").c_str())
>
> (The policy uses conversion functions described below.)
>
>
>
As long as you can prove the text is ASCII, it won't break. As soon as you
can have other encodings (even if it's one of the supported "ANSI code
pages") you need to have stricter control of strings origins and
manipulation. For instance, windows code page can in theory support even
utf8. Or japanese multi-byte encoding, even in the non-wide (non-UNICODE)
flow. Or the common european several 8-bit encodings windows supports, etc.
You don't need to use the utf8 approach to deal with this, but if you your
program starting to grow and you need to deal with multiple ansi code pages
and windows API, and data from different sources, you'll probably end up
with unavoidable spaghetti code and bugs lying around, so you'd probably
have a gain to deal with it from the beginning.
The windows way of dealing with this is to use the wide api (-DUNICODE
and/or "W" ending functions) and deal with converting to/from utf16. It
works and is commonplace.
What I don't like is the fact that you most likely end up using a lot of
wchar_t (or std::wstring) around. Not every library has overloads for
std::wstring so you end up having to convert to/from it, which is spaghetti
and burning cpu cycles, but at least is type safe (i.e. you'll *have* to
explicitly convert it), it could be worse.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public