Windows中的非 ASCII 文件路径

我在Windows上工作,并使用带有非ASCII符号的文件路径。对于非 ASCII 符号,Windows 使用 wstring。我正在进行转换并将它们传递给 luaL_dofile,但是它无法找到文件。

以下是我的代码示例:

std::wstring wstr_path = "非 ASCII 路径"

using convert_type = std::codecvt_utf8_utf16<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
std::string str_path = converter.to_bytes(wstr_path);
luaL_dofile(mRoot, str_path.c_str());
点赞
用户219159
用户219159

我对luaL_dofile一无所知,但它很可能不使用UTF-8。对于不支持Unicode的程序,Windows文件API使用ANSI代码页(对应于系统默认本地设置)。英语/美国系统上的ANSI代码页为1252,但其他系统默认本地设置有不同的代码页,例如中欧为1250,西里尔语为1251等。

另外,您可以尝试为文件生成短名称(参见GetShortPathName API),然后将其提供。

2020-06-12 20:56:24