Unexpected encoding issue with _() macro and UTF-8 source in Unicode build (wxWidgets 3.3.1)
Claudio Fabiano Rossato <[email protected]> Fri, 14 Nov 2025 16:22:55 +0100
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hello everyone,
I'm encountering an unexpected encoding issue with string literals in a
Unicode build of a wxWidgets application, and I’d appreciate any insights.
*Environment*
*
wxWidgets: 3.3.1
*
OS: Windows 11
*
Source files: UTF-8 with BOM
*
Compiler: Visual Studio 2022 with |/utf-8|
*
wxWidgets build: Unicode (UTF-16 internally)
*Problem*
Using the standard |_()| macro on a UTF-8 string literal containing
Italian accented characters results in a corrupted |wxString|. It looks
like the UTF-8 bytes are interpreted as single-byte characters.
*Examples*
Code Debug Output Result
|wxString msg1 = _("Prova di log con accenti: è ò à ì ù");| |L"Prova di
log con accenti: è ò à ì ù"| Corrupted
|wxString msg2 = _(wxS("Prova di log con accenti: è ò à ì ù"));|
|L"Prova di log con accenti: è ò à ì ù"| Correct
*Clarification*
I understand that |wxS()| fixes the issue because it turns the literal
into a wide string (|L"..."|).
What confuses me is that I expected |_()| alone to be sufficient, since
the source file is UTF-8 and MSVC is instructed to treat all narrow
literals as UTF-8 via |/utf-8|.
*My question*
Is it expected that |_()| still interprets narrow string literals
according to the system code page (CP1252) instead of UTF-8, even when
the compiler is set to UTF-8?
In other words: in a Unicode build, is using |wxS()| (or |FromUTF8|) the
intended and required way when dealing with UTF-8 source files?
Thanks a lot for any clarification.
Best regards,
Claudio Rossato
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/6f9253b4-d2bd-458f-a773-49851412eeac%40gmail.com.