Comment 4 for bug 1095038

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