You're trying to convert apples into oranges here. MultiByteToWideChar and WideCharToMultiByte convert between specific encodings, UTF-16 <-> a variety of other encodings, including ANSI.
3 problems:
- The encoding to which the char <-> wchar_t functions in the C standard library operates is implementation defined. It could translate between UCS-2 and ASCII, or EBDIC, or any number of other codepages. You can't replace the windows functions with these because you can't assume wcstombs and mbstowcs actually are talking about UTF-16, or actually talking about ASCII. Usually the actual encoding they use is UTF-32 on unix boxes.
- Unix boxes don't often recognise UTF-16 -- they're all UTF-8 based, if they support unicode at all.
wchar_t
is typically 4 bytes on unix boxes, not 2 bytes, so you'd have to check all of your code to ensure that the size of it was never assumed to be 2 bytes.
Simply put, there is no completely portable way of dealing with these kind of things unless you write the code to do the encoding yourself.
If you want to be portable, you need to define a typedef or something so that your application uses wchar_t on windows, and char on everything else. You then must assume that UTF-16 is being used on Windows boxes, and UTF-8 is being used on unix boxes.
OR: You have to use a library, such as ICU.