Question

I am trying to convert a std::string Buffer - containing data from a bitmap file - to std::wstring.

I am using MultiByteToWideChar, but that does not work, because the function stops after it encounters the first '\0'-character. Seems like it interprets it as the end of the string.

When i dont pass -1 as the length-parameter, but the real length of the data in the std::string-Buffer, it messes the Unicode-String up with characters that definetly not appeared at that position in the original string...

Do I have to write my own conversion function? Or maybe shall i keep the data as a casual char-array, because the special-symbols will be converted incorrectly?

With regards

Was it helpful?

Solution

There are many, many things that will fail with this approach. Among other things, extra bytes may be added to your data without your realizing it.

It's odd that your only option takes a std::wstring(). If this is a home-grown library, you should take the trouble to write a new function. If it's not, make sure there's nothing more suitable before writing your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top