求教如何实现同一串口在不同程序间的共享?CreateFile的共享参数File_Share_Read等本人试用无效,不知是真无效还是使用的问题。

解决方案 »

  1.   

    串口只能打开一次,不能共享,MSDN中说打开串口时CreateFile的参数如下
    m_hComm = CreateFile("COM1", // communication port string (COMX)
    GENERIC_READ | GENERIC_WRITE, // read/write types
    0,  // comm devices must be opened with exclusive access
    NULL, // no security attributes
    OPEN_EXISTING, // comm devices must use OPEN_EXISTING
    FILE_FLAG_OVERLAPPED, // Async I/O 
    0); // template must be 0 for comm devices
      

  2.   

    Communications Resources
    The CreateFile function can create a handle to a communications resource, such as the serial port COM1. For communications resources, the dwCreationDisposition parameter must be OPEN_EXISTING, and the hTemplate parameter must be NULL. Read, write, or read/write access can be specified, and the handle can be opened for overlapped I/O. For more information about communications, see Communications. 说明未表明不能共享呀?