How do I get an old VC++ 6.0 MFC program to read and display UTF8 in a TextBox or MessageBox? Preferably without breaking any of the file reading and displaying that is currently written in there (fairly substantial).
I read a line into CString strStr, then used this code:
int nLengthNeeded = MultiByteToWideChar(CP_UTF8,0,strStr,1024,0,0); wchar_t * pWCMessage = new wchar_t[ nLengthNeeded ]; MultiByteToWideChar(CP_UTF8,0,strStr,1024,pWCMessage,nLengthNeeded); nLengthNeeded = MultiByteToWideChar(CP_UTF8,0,'Error Title',50,0,0); wchar_t * pWCTitle = new wchar_t[ nLengthNeeded ]; MultiByteToWideChar(CP_UTF8,0,'Error Title',50,pWCTitle,nLengthNeeded); MessageBoxW(NULL,pWCMessage,pWCTitle,MB_ICONINFORMATION);
Still not sure how I would get it into a textbox, but it turns out I don’t need to do that anyway.
I feel like this won’t be helpful, but it’s a starting point… I’m assuming it doesn’t ‘just work’, and I don’t think you want to try to screw around with wacky code pages that may or may not get you what you want.
How about just using MultiByteToWideChar(CP_UTF8, …) to convert it to utf16 and then calling the W versions of those functions (or defining UNICODE/_UNICODE for the project).
I know that will work for MessageBox, and I can’t imagine the text box doesn’t have unicode support.
If you need to get the output back to UTF8 – just use WideCharToMultiByte().