I need to convert file names from System.String
into std::string
. I am using both Japanese and English file names.
For English file names, there is no issue.
Only Japanese file names are not converting to std::string
in English Windows 10.
I used WideCharToMultiByte()
and code page 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;
}
Here str
is "C:\\files\\ブ種別.pdf"
convertedstring
is "C:\\files\\ƒuŽí•Ê.pdf"
Can anyone help me to resolve this?