用多线程来处理多个窗口,都是用CreateFile打开,测试人员说COM10及以后就无法打开,也无法操作,COM1--COM9没有问题大家有没有碰到过相关的问题?是不是有什么限制或者格式限制?多谢多谢!

解决方案 »

  1.   

    gohappy_1999(碧水蓝天)说得对,COM10以上必须加 \\.\ 前缀,可以看看MSDN里面的描述。CreateFile() can be used to get a handle to a serial port. The "Win32 Programmer's Reference" entry for "CreateFile()" mentions that the share mode must be 0, the create parameter must be OPEN_EXISTING, and the template must be NULL.CreateFile() is successful when you use "COM1" through "COM9" for the name of the file; however, the message "INVALID_HANDLE_VALUE" is returned if you use "COM10" or greater.If the name of the port is COM10, the correct way to specify the serial port in a call to CreateFile() is as follows:CreateFile(
       "\\\\.\\COM10",    // address of name of the communications device
       fdwAccess,         // access (read-write) mode
       0,                 // share mode
       NULL,              // address of security descriptor
       OPEN_EXISTING,     // how to create
       0,                 // file attributes
       NULL               // handle of file with attributes to copy
       );NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well.
      

  2.   

    我自己从msdn.microsoft.com上createfile,没看到这段描述啊.不过确实是这样解决问题的,谢谢大家.