WriteFile to Parallel port hangs

2019-08-12 06:27发布

I am writing an activex control that will access the parallel port and write the bytes to it. I am able to open the port succesfully but when i write it hangs at WriteFile function. Did i miss anything here? I am using 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条回答
何必那么认真
2楼-- · 2019-08-12 07:08

If the port's output buffer is full then WriteFile will hang until there is room to complete your request. Is there something attached to the port and reading from it?

查看更多
登录 后发表回答