WriteFile to Parallel port hangs

烈酒焚心 提交于 2019-12-11 09:05:29

问题


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:


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?



来源:https://stackoverflow.com/questions/9664463/writefile-to-parallel-port-hangs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!