Reputation: 989
I have to use a library that accepts file names as strings (const char*
). Internally files are opened with fopen
. Is there a way to make this library to accept unicode file name? Can I use WideCharToMultiByte to convert unicode names into utf before passing them to the library?
One possible (undesirable) solution is to change library interface (char* -> wchar_t*
) and replace fopen
with windows specific _wopen
. Another solution is to use create symbolic links to files and pass those to the library, but it is limited to NTFS volumes only.
Upvotes: 3
Views: 8535
Reputation: 15385
Best way would be to rewrite the lib... Just my 2 Cents.
But if it is just about to open an existing file you can use GetShortPathName You find an existing discussion about this way here.
Upvotes: 5
Reputation: 18531
Using WideCharToMultiByte you are only able to open files that have file names that contain only ANSI characters. This is because the ANSI variants (using a "char *" type argument) of file functions are not able to open files that contain characters above 255 in the file name.
Using GetShortPathName has the disadvantage that it might not work on certain file systems (maybe certain types of network drives) that do not support "8.3" file names.
I would rewrite the library using the "_wfopen" function (the UNICODE equivalent of "fopen" is "_wfopen", not "_wopen").
Please note that the second argument of "fopen" must also be an UNICODE string when using _wfopen.
Upvotes: 2