How to open a file named UNICODE in Windows?

There is a 3rd library only accepting char * filename for example. 3rdlib_func_name(char* file_name)

... Everything goes wrong when I provide the file name in Chinese or Japanese.

Is there a way to make this lib open UNICODE file name? The program runs on Windows .

Thanks for your reply.

+2


a source to share


3 answers


We also have a similar problem. Fortunately, there is a solution, although it is quite difficult.

If the file / directory already exists, you can use the function GetShortPathName

. The resulting "short" pathname is guaranteed to contain no non-Latin characters.



  • Call GetShortPathNameW

    (Unicode version) to get the "short" path string.
  • Convert short path to ANSI string (use WideCharToMultiByte

    ).
  • Give the resulting ANSI string for a silly third party library.

Now, if the file / directory doesn't already exist, you might not get its short name. In this case, you must create it first.

+4


a source


No, no, unless you can recompile it from the modified source (basic obligation). You might be in luck if you feed third-party library names with short filenames like AHDF76~4.DOC

; these filenames use ASCII. Cm GetShortPathName

.



+1


a source


You can try to convert the string to a local codepage:

setlocale(LC_ALL,"Japanese_Japan.932");
std::string file_name = convert_to_codepage_932(utf16_file_name);
3rdlib_func_name(file_name.c_str());

      

Otherwise?

Lock windows for UTF-8 support ;-)

0


a source







All Articles