CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    SetCommState Problem

    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.
    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();
    }
    Is this somehow because I am using mingw?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: SetCommState Problem

    Quote Originally Posted by jnmacd View Post
    ...
    Is this somehow because I am using mingw?
    Perhaps...
    Because it never happens if using MS IDE (any version)
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2002
    Posts
    2,543

    Re: SetCommState Problem

    What happens if you exclude all Qt-related code from this program?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured