I am using Qt with the mingw compiler.
I'm having a problem with the SetCommState function from the Windows API.
It seems like any time I run SetCommState, it will get itself into an infinite loop. The program eventually crashes, and checking the call stack shows hundreds of calls into SetCommState.
However, if another program, such as PuTTy or a program compiled in Visual Studios opens the COM port first, then my program will work.
Even this simple program will reproduce the problem.
Is this somehow because I am using mingw?Code:
#include <QtCore/QCoreApplication>
#include <windows.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
DCB dcb;
HANDLE com = CreateFileA("COM5", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (com == INVALID_HANDLE_VALUE)
{
qDebug("Invalid handle");
return -1;
}
qDebug("GetCommState");
GetCommState(com, &dcb);
qDebug("SetCommState");
SetCommState(com, &dcb); // <-- infinite loop here
qDebug("Done.");
return a.exec();
}

