MultiByteToWideChar

Hi, trying to get characters, such as ä, ê, and so on, out of a file, so, I try and convert an std::string, gotten from the file, to a std::wstring, using, in the mean time, MultiByteToWideChar (win api).

This gives, unfortunately, using GetLastError, following error code:


ERROR_INVALID_FLAGS

1004 (0x3EC)
Invalid flags.


Code, is:
1
2
3
4
5
6
ifstream *inFile = new ifstream(szFile);
	std::string szFileStr((std::istreambuf_iterator<char>(*inFile)),std::istreambuf_iterator<char>());
	LPWSTR s[10000];
	int a= MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED,szFileStr.c_str(),-1,*s,10000);
	std::cout << GetLastError() << std::endl;
	std::wstring szwFileStr = std::wstring(*s);
From

MultiByteToWideChar function
http://msdn.microsoft.com/en-us/library/dd319072%28v=vs.85%29.aspx

Note For UTF-8 or code page 54936 (GB18030, starting with Windows Vista), dwFlags must be set to either 0 or MB_ERR_INVALID_CHARS. Otherwise, the function fails with ERROR_INVALID_FLAGS.

i.e. you cannot use MB_PRECOMPOSED with UTF-8

Andy
Topic archived. No new replies allowed.