Re: Handling multi-language files
"cjb" <cjb@discussions.microsoft.com> wrote in message
news:17830ED3-3CCF-4A97-8377-4DBD236C2904@microsoft.com...
Both the file name and the contents are multi-lang and the FILE type is
returning NULL.
For example:
FILE *fd;
if ((fd = _fsopen((char *)wName, "rb", _SH_DENYRW)) == NULL) {
printf("** Error opening file.\n");
}
I assume that wName type is wchar_t. If that's the case then this shouldn't
work because you're passing Unicode characters to a function that expects
ASCII ones. (Remember, whenever you need a type-cast you're mostly doing
somthing wrong)
This works (obviously):
if ((fd = _wfsopen(wName, L"rb", _SH_DENYRW)) == NULL) {
printf("** Error opening with wide filename.\n");
}
Right...
And this does NOT work:
WideCharToMultiByte(CP_ACP, 0, wName, -1, cName, 1024, NULL, NULL)
if ((fd = _fsopen(cName, "rb", _SH_DENYRW)) == NULL) {
printf("** Error opening with multi-byte filename.\n");
}
Because you're passing multi-byte characters to a function that expects
unicode ones, why don't you just use this:
_wfsopen(wName, L"rb", _SH_DENYRW); // Note the function and the
parameter used
For both English and other multilingual file names... Of course you should
initialize wName probably in order to get it right
Of course this would only solve the problem of opening the file. As for
reading the file the method is very similar (Always use a wchar_t and a
w-function when using Unicode)
Hope that helps,
--
Abdo Haji-Ali
Programmer
In|Framez