方法如下:
bool LptPrint(char prtdata[],int prtlen,int timeout)
{
HANDLE h;
DWORD n;
COMMTIMEOUTS t;
bool result;
h = CreateFile("lpt1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (h == INVALID_HANDLE_VALUE){
AfxMessageBox("Can not open lpt1");
return false;
}
t.ReadIntervalTimeout = 0;
t.ReadTotalTimeoutMultiplier = 0;
t.ReadTotalTimeoutConstant = 0;
t.WriteTotalTimeoutMultiplier = timeout * 1000 / prtlen;
t.WriteTotalTimeoutConstant = 0;
if (!SetCommTimeouts(h,&t)){
AfxMessageBox("SetCommTimeout error");
return false;
}
result = true;
if (!WriteFile(h,prtdata,prtlen,&n,NULL)){
AfxMessageBox("Print error");
result = false;
}
CloseHandle(h);
return result;
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/