Menu

CreateFile() fails for CNCA0

Help
2005-12-01
2013-05-20
  • Jonathan Taylor

    Jonathan Taylor - 2005-12-01

    With version 1.4.0.0 of com0com, the HyperTerminal test succeeds, but I get a failure when trying to open the port with CreateFile():

    m_hComm = CreateFile("CNCA0", 
                        GENERIC_READ | GENERIC_WRITE,
                        0,
                        0,
                        OPEN_EXISTING,
                        FILE_FLAG_OVERLAPPED,
                        0);

    GetLastError() returns ERROR_FILE_NOT_FOUND.

    Should I be using a different device name (other than "CNCA0")?  I tried a few other variations.

    Thanks

     
    • Jonathan Taylor

      Jonathan Taylor - 2005-12-01

      Excellent question, Jonathan ;>

      With device names of this type, you need to prefix them with \\.\, as in:

      \\.\CNCA0

       
    • elbreton

      elbreton - 2009-06-22

      Hello !

      I tried to use CreateFile as described in the ReadMe & here, but without being successful ...

      HANDLE h = CreateFile(    (LPCWSTR)"\\\\.\\CNCA0",
                                  GENERIC_READ | GENERIC_WRITE,
                                  0,
                                  NULL,
                                  OPEN_EXISTING,
                                  FILE_ATTRIBUTE_SYSTEM,
                                  NULL
                              );

      The test with the Hyperterminal is ok. I don't have so much knowledges about COM ports, and my google searches didn't get me any further ...

      So ... Any tip to get a step ahead would be very welcome ;)

      Thanks

      J

       
    • elbreton

      elbreton - 2009-06-22

      In case another one would forget about UNICODE / ANSI stuff ...

      The answer is contained in the previous line.

       
    • Vyacheslav Frolov

      > HANDLE h = CreateFile( (LPCWSTR)"\\\\.\\CNCA0",

      Try to replace (LPCWSTR) by TEXT():

        TEXT("\\\\.\\CNCA0"),

      > FILE_ATTRIBUTE_SYSTEM,

      Why is it?

       

Log in to post a comment.