WriteFile到并行端口挂起

时间:2012-03-12 09:25:09

标签: c++ windows winapi parallel-port

我正在编写一个activex控件,它将访问并行端口并将字节写入其中。我能够成功打开端口但是当我写它时会挂起WriteFile函数。我在这里错过了吗?我正在使用Windows 7

HANDLE portHwd = CreateFile( _T("\\\\.\\LPT1" ), 
                        GENERIC_WRITE,
                        0,
                        NULL,
                        OPEN_EXISTING,
                        0,
                        NULL); 
      if (portHwd)
      {
          char outBuffer[] = _T("This is a test\r\n");
          int sz_buffer = strlen(outBuffer);

            DWORD bytes_written;
            if (!WriteFile( portHwd,
                  outBuffer,  
                  sz_buffer , 
                  &bytes_written, 
                  NULL))
            {
                  CloseHandle(portHwd);
                  GetLastError();
                  return 1;
            }

            CloseHandle(portHwd);
      }

1 个答案:

答案 0 :(得分:1)

如果端口的输出缓冲区已满,则WriteFile将挂起,直到有空间完成您的请求。是否有东西附在港口并从中读取?