Search code examples
windowswinapiwxwidgets

CreateFile fails in wxWidgets


I am trying to open the serial port, Below is the code and the CreateFile always return INVALID_HANDLE_VALUE. Can someone help me this.

wxString port = "COM13";

HANDLE hComm = CreateFile( port.wc_str(),  
                GENERIC_READ | GENERIC_WRITE, 
                0, 
                NULL, 
                OPEN_EXISTING,
                FILE_FLAG_OVERLAPPED,
                NULL);

if (hComm == INVALID_HANDLE_VALUE)
{
    WxListBox_Log->Append("Unable to connect " + port.c_str());
}

Solution

  • You need to use the following file name: "\\\\.\\COM13".

    See details in this article: http://support.microsoft.com/kb/115831

    HOWTO: Specify Serial Ports Larger than COM9