如何在Windows上打开具有UNICODE文件名的文件? [英] How to open a file with UNICODE filename on Windows?
问题描述
第3个库仅接受char *文件名,例如3rdlib_func_name(char* file_name)
.当我提供中文或日语文件名时,一切都会出错.
There is a 3rd lib only accept char* filename e.g. 3rdlib_func_name(char* file_name)
. Every things get wrong when I provide a filename in Chinese or Japanese.
有什么办法可以使这个lib打开UNICODE文件名?该程序正在 Windows 上运行.
Is there any way to make this lib open UNICODE filename? The program is running on Windows.
感谢您的答复.
推荐答案
我们也有类似的问题.幸运的是,有一个解决方案,尽管有点棘手.
We has a similar problem too. Luckily there's a solution, though it's kinda tricky.
如果文件/目录已经存在-您可以使用GetShortPathName
函数.保证生成的短"路径名不包含非拉丁字符.
If the file/directory already exists - you may use the GetShortPathName
function. The resulting "short" path name is guaranteed not to contain non-latin characters.
- 调用
GetShortPathNameW
(Unicode版本)以获取短"路径字符串. - 将短路径转换为ANSI字符串(使用
WideCharToMultiByte
). - 将生成的ANSI字符串提供给愚蠢的第三方库.
- Call
GetShortPathNameW
(unicode version) to get the "short" path string. - Convert the short path into the ANSI string (use
WideCharToMultiByte
). - Give the resulting ANSI string to the stupid 3rd-party lib.
现在,如果文件/目录尚不存在-您可能无法获得其短路径名.在这种情况下,您应该先创建它.
Now, if the file/directory doesn't exist yet - you may not obtain its short pathname. In such a case you should create it first.
这篇关于如何在Windows上打开具有UNICODE文件名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!