【问题标题】:non-ASCII file paths Windows非 ASCII 文件路径 Windows
【发布时间】:2020-06-12 20:52:36
【问题描述】:

我在 Windows 上工作,并且文件路径包含非 ASCII 符号。对于使用 wstring 的非 ASCII 符号窗口。我正在进行转换并将它们传递给 luaL_dofile 但它失败了,找不到文件。

这是我的代码示例:

std::wstring wstr_path = "non-ASCII path"

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());

【问题讨论】:

  • 我检查了来源。 luaL_dofile 调用 luaL_loadfilex,后者调用 C fopen。对于 Windows C 运行时,fopen 解码来自进程活动 (ANSI) 代码页的文件名并调用 CreateFileW。在这里获得全部 Unicode 的唯一方法是在可执行文件的清单中将活动进程代码页设置为 UTF-8,这只能在 Windows 10 中实现。

标签: c++ windows luajit wstring


【解决方案1】:

我对@9​​87654321@ 一无所知,但它不太可能使用 UTF-8。用于 Unicode 未知程序的 Windows 文件 API 使用 ANSI 代码页(对应于系统默认区域设置)。英语/美国系统上的 ANSI 代码页是 1252,但其他系统默认语言环境具有不同的代码页。中欧是 1250,西里尔文是 1251,等等。

此外,您可以尝试生成文件的短名称(请参阅GetShortPathName API)并提供它。

【讨论】:

    猜你喜欢
    • 2020-10-03
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多