Working on a NON-UNICODE international app(C/C++ on Windows) that can import files with polish characters. Using a Polish Locale as well.
Locale=pl-PL (set in app via "setlocale(LC_ALL, localeSetting)")
LocaleID=1045
CharSet=238
This feature worked correctly on previous releases but in this last year we updated our file open/file save dialogs from the old vista style to the much more current Common Item File Dialogs. The following error occurs directly after capturing the input text from the file open dialog. Ergo its nothing within our application but the common item dialog directly. The dialog captures the incoming file path as a PWSTR (wide string) and we convert that over to a multi-byte string to pass it back over to our app from the common item dialog.
code in which error is happening within Common Item Dialog code:
PWSTR FilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &FilePath);
if (SUCCEEDED(hr))
{
char temp_mbarray[MAX_SIZE_PATH];
if (wcstombs(temp_mbarray, FilePath, MAX_SIZE_PATH) > 0)
{
std::string pass_back_string(temp_mbarray);
*results = pass_back_string;
}
}
The correct polish file name: "kołozębate"
Original filename result with the c-style translation( using wcstombs() ) is "koÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ..."
It seemingly gets the first two characters k-o correctly since they aren't inherently Polish, but as soon as it encounters a Polish character it goes just fills the rest of the array with the Ì character. ends up being much longer than original filename.
Swapped over to a windows style conversion from wide char to multi-byte string( WideCharToMultiByte() ):
PWSTR FilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &FilePath);
if (SUCCEEDED(hr))
{
char temp_mbarray[MAX_SIZE_PATH];
int wcs_length = int(wcslen(FilePath)) + 1;
if(WideCharToMultiByte(CP_UTF8, 0, FilePath, wcs_length, temp_mbarray, MAX_PATH, nullptr, nullptr) > 0)
{
std::string pass_back_string(temp_mbarray);
*results = **strong text**;
}
}
"kołozębate" is the result after the change over to WideCharToMultiByte() which seems like a vast improvement, but seems that all the special characters that are uniquely Polish in this case are just unknown, or converted incorrectly. Not really sure