Did you know you can make a Windows Win32 application use UTF-8 for char* strings? Did you think it had to be WCHAR for all that? Well Microsoft made some changes…
It’s not even a big change to make. You just need to add this application manifest and you’re done! Your main copdepage will now be UTF-8 and your char* and std::strings will be able to hold Unicode characters. You can then call the A versions of functions instead of W and get all the benefits of UNICODE, for instance MessageBoxA() instead of MessageBoxW().
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyIdentity type="win32" name="Win32DirectX12" version="18.104.22.168"/> <application> <windowsSettings> <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage> </windowsSettings> </application> </assembly>
You can also add
/utf-8 to let the compiler know that your code is UTF-8. This doesn’t seem to help as much as you’d wish as any string literals in your code will not be converted to UTF-8 even if you paste in the characters. You may also encounter issues where the strings interact with visual studio or any other IDEs. Getting text from your UI input seems to work as you’d expect and hope.