Image Writer for Windows

Error message encoding is messed up

Reported by Andrei Lisin on 2013-01-01
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Image Writer
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

Andrei Lisin (terranium) wrote :
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) on 2013-01-02
Changed in win32-image-writer:
status: Triaged → Fix Committed
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

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));

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) on 2013-02-03
Changed in win32-image-writer:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers