I\'m using ReadFile()
on Windows to read data from a serial port. This code was working fine at one point in time, but it\'s now failing and I\'m trying to trac
The constructor of QMessageBox may be doing something that clears `GetLastError'. Try this:
if (!ReadFile(hGpsUart, buf, 160, &bytes_read, NULL))
{
int LastError = GetLastError() ;
QMessageBox msg;
msg.setText(QString("Error %1 reading from GPS UART!").arg(LastError));
msg.exec();
}
I think the key to your observations is the phrase in your source that says "Yet in here, GetLastError() returns ERROR_SUCCESS (0)"
The call to GetLastError has to be the very next Win32 call made after the (presumably) failing call. As an experiment, try putting an explicit call to GetLastError() within your failure handler, but just before the message box call. I suspect you'll see the true failure code.
Good luck!