Error message encoding is messed up

Bug #1095038 reported by Andrei Lisin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Image Writer
Fix Released
Medium
Tobin Davis

Bug Description

In getHandleOnFile legacy encoding is used for error message and Qt fails to understand it, as a result localized error message is unreadable. Apparently Qt assumes 1252, while actual ANSI encoding is system-defined and can be changed in system settings. The system itself doesn't depend on the setting as it natively works in unicode and ANSI api is supported for backward compatibility with software written for win9x. Use unicode strings and unicode winapi instead - FormatMessageW instead of FormatMessageA.
Read about unicode in windows: http://msdn.microsoft.com/en-us/library/windows/desktop/dd374081.aspx

Revision history for this message
Andrei Lisin (terranium) wrote :
Revision history for this message
Tobin Davis (gruemaster) wrote :

Thanks for the tip. I'll add this to my immediate todo for the next release update.

Changed in win32-image-writer:
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → Tobin Davis (gruemaster)
Tobin Davis (gruemaster)
Changed in win32-image-writer:
status: Triaged → Fix Committed
Revision history for this message
Tobin Davis (gruemaster) wrote :

I've made the required modifications and pushed them to sourceforge. Please test this version to see if it works (if you can reproduce the error).

Also, this is the first build from this build environment (Windows 7, QT 4.84). I'm not sure if it still supports 32bit or not (should).

MD5sum:
4e3c1f4349aa47f5502630b1de901616 *win32imagewriter-0.6+fixes.zip

Revision history for this message
Andrei Lisin (terranium) wrote :

I didn't try it yet, but the code seems wrong. Did you test it? You'll get utf16 text in errormessage, so it shouldn't be declared char* as char is supposed to be used for encodings compatible with ASCII, i.e. zero byte means end of string. In utf16 is 2-byte encoding and you can get zero byte very often, e.g. for all ASCII characters. So you'll probably get only the first byte from the message as the second byte will be zero if Qt doesn' doesn't detect utf-16 heuristically, but I wouldn't rely on heuristics. I suggest to declare WCHAR *errormessage. Qt should understans it.
Like this:

WCHAR *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QMessageBox::critical(NULL, "File Error", QString("An error occurred when attempting to get a handle on the file.\nError %1: %2").arg(GetLastError()).arg(errormessage));

Revision history for this message
Tobin Davis (gruemaster) wrote :

I am working on redoing these completely. I am also working on implementing translatable text strings. Should have another release very soon.

Tobin Davis (gruemaster)
Changed in win32-image-writer:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.