ReadFile() says it failed, but the error code is ERROR_SUCCESS

后端 未结 2 469
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 11:41

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

2条回答
  •  抹茶落季
    2021-01-15 12:17

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

提交回复
热议问题