gpt4 book ai didi

c++ - WriteFile 到并行端口挂起

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:21 26 4
gpt4 key购买 nike

我正在编写一个 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);
}

最佳答案

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

关于c++ - WriteFile 到并行端口挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9664463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com