If you're calling Win32 functions it's already not compatible with other OSes... If you want to use cross platform code with files, use the C or C++ standard library's file handling functions.
C++ also supports wstring, but its implementation is dependent on the platform for god knows what reason.
utf-16 is also supported in C11:
https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Chan...
> Improved Unicode support based on the C Unicode Technical Report ISO/IEC TR 19769:2004 (char16_t and char32_t types for storing UTF-16/UTF-32 encoded data, including conversion functions in <uchar.h> and the corresponding u and U string literal prefixes, as well as the u8 prefix for UTF-8 encoded literals).
You can use uchar.h for converting instead of the Win32 functions.
Here's a helper I wrote to wrap these string types in std::string and std::wstring:
bool mbStrToWideChar(string const& in, wstring& out)
{
bool status = true;
i32 bufferSize = MultiByteToWideChar(
CP_ACP, 0, in.c_str(), -1, nullptr, 0
);
WCHAR* buffer = new WCHAR[bufferSize];
i32 conversionResult = MultiByteToWideChar(
CP_ACP, 0,
in.c_str(), -1,
buffer, bufferSize
);
if (!conversionResult)
{
cerr << "Failed to convert ANSI string [" << in << "] to Wide string!" << endl;
status = false;
goto Delete;
}
out = wstring(buffer);
Delete:
if (buffer)
{
delete[] buffer;
}
return status;
}
and
bool wideStrToMbStr(wstring const& in, string& out)
{
// Get buffer size
i32 bufferSize = WideCharToMultiByte(
CP_UTF8, 0,
in.c_str(), (i32)in.size(),
nullptr, 0,
nullptr, nullptr
);
// Set outstring to new buffer size
out = string(bufferSize, '\0');
//Convert
i32 res = WideCharToMultiByte(
CP_UTF8, 0,
in.c_str(), (i32)in.size(),
&out[0], (i32)out.size(),
nullptr, nullptr
);
if (!res)
{
wcerr << L"Failed to convert Wide string [" << in << L"] to ANSI string!" << endl;
return false;
}
return true;
}