WideCharToMultiByte在英语操作系统上不转换日语

WideCharToMultiByte not converting Japanese on English OS

本文关键字:转换 日语 操作系统 英语 WideCharToMultiByte      更新时间:2023-10-16

我需要将文件名从System.String转换为std::string。我同时使用日语和英语文件名。

对于英文文件名,没有问题。

只有日语文件名不会转换为英语 Windows 10 中的std::string

我使用了WideCharToMultiByte()和代码页 932。

std::string marshal_as(System::String^ str)
{
std::string convertedstring;
size_t _size = 0;
cli::pin_ptr<const wchar_t> _pinned_ptr = PtrToStringChars(str);
_size = WideCharToMultiByte(932, 0, _pinned_ptr, str->Length, 0, 0, 0, 0);
if (_size > 0)
{
convertedstring.resize(_size);
char* buffer = &convertedstring[0];
WideCharToMultiByte(932, 0, _pinned_ptr, -1, &buffer[0], _size, 0, 0);
}
return convertedstring;
}

这里str"C:\files\ブ種別.pdf"

convertedstring"C:\files\ƒuŽí•Ê.pdf"

谁能帮我解决这个问题?

我的问题已修复。我启用了测试版:在控制面板的区域设置中使用 Unicode UTF-8 进行全球语言支持选项。