C++ Multi-Byte - prepare string of extensions for OpenFileDialog

Started by
11 comments, last by mynameisnafe 9 years, 9 months ago


std::transform(str.begin(),str.end(),back_inserter(ext),[](char t) -> wchar_t { return t == ';' ? 0 : t; });

I don't think that's actually going to do the right thing if there's anything other than US ASCII in the original string. A simple integral promotion from a multibyte UTF-8 string into Microsoft's proprietary UCS-2 wide-character Unicode variant is a fail.

Of course, if you're restricting your somain to US ASCII, you're fine.

Microsoft hasn't used UCS-2 since Windows 2000. All modern versions of Windows use UTF-16 which is a multibyte encoding the same as UTF-8. Converting a UTF-8 string to UTF-16 is not going to make it easier to process.

http://www.utf8everywhere.org/

Advertisement

If you are going to hard-code an L"" string, you are required to use the W version of OPENFILENAME (OPENFILENAMEW) and GetOpenFileName (GetOpenFileNameW).

Never mix-and-match "", _T( "" ), and L"" strings.

The solution is to convert from UTF-8 to wide-character strings via MultiByteToWideChar() (passing CP_UTF8) and use OPENFILENAMEW and GetOpenFileNameW() to open the file.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

L. Spiro replies to my thread? Honoured!

I shall give it a try in 5 mins and let you guys know what happened..

This topic is closed to new replies.

Advertisement