【发布时间】:2010-06-01 17:11:16
【问题描述】:
如何从 Unicode 路径名 (LPWSTR) 转换为 ASCII 等价物?被调用的库只理解 c 字符串。
编辑: 好的,我接受了 GetShortPathName 和 WideCharToMultiByte 建议并创建了那段代码,我用路径中包含 Unicode 字符的一些文件夹对其进行了测试,它完美地工作:
wlength = GetShortPathNameW(cpy,0,0);
LPWSTR shortp = (LPWSTR)calloc(wlength,sizeof(WCHAR));
GetShortPathNameW(cpy,shortp,wlength);
clength = WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortp, wlength, 0, 0, 0, 0);
LPSTR cpath = (LPSTR)calloc(clength,sizeof(CHAR));
WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortp, wlength, cpath, clength, 0, 0);
【问题讨论】: