再试一次 - 将ascii命令字符串写入虚拟打印机 [英] try again - Writing ascii command strings to a virtual printer

查看:131
本文介绍了再试一次 - 将ascii命令字符串写入虚拟打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要从文本文件中读取一些ascii命令,然后一次将它们输出到虚拟打印机,这是一个USB并行端口。该设备名为Generic / Text Only,使用名为USB Printing Support的驱动程序通过名为USB001的端口进行访问。我可以使用带有上述信息的CreateDC,然后使用dc来绘制文本等,但它增加了一大堆开销。我可以使用任何纯文本方法吗? (记得打印和LPrint吗?)万一你感兴趣,我必须一次写一行,因为虚拟设备的缓冲区非常有限。



任何帮助将不胜感激!



好​​的,也许太多的信息使问题蒙上阴影。让我重申一下吧!



我有一个MSVC ++ MFC应用程序需要将空终止的C风格字符串写入通过USB连接到并行端口设备的虚拟打印机。在名为USB001的端口上使用名为USB Printing Support的驱动程序,设备名称为Generic / text only。将字符串送到打印机的最佳方法是什么?



再次感谢您的期待!

I have an application that needs to read some ascii commands from a text file and then output them one line at a time to a virtual printer which is a USB parallel port. The device is named "Generic / Text Only" and it is accessed thru a port named "USB001" using a driver named "USB Printing Support". I can use CreateDC with the above info and then use the dc to draw text etc but it adds a whole bunch of overhead. Is there any plain text method that I can use? ( remember Print & LPrint??) Just in case you''re interested, I have to write one line at a time because the virtual device has a very limited buffer.

Any help will be appreciated!

OK, Maybe too much information clouded the question. Let me restate it!

I have a MSVC++ MFC application that needs to write null terminated C-style strings to a virtual printer attached via a USB to Parallel port device. The device name is "Generic / text only" using a driver named "USB Printing Support" on a port named "USB001". What is the best way to get the strings to the printer?

Thanks again for looking!

推荐答案

您可以尝试使用 CreateFile()打开设备并写入:

You can try to use CreateFile() to open the device and write to it:
HANDLE hDevice = ::CreateFile(_T("\\\\.\\USB001"), 
    GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0);
if (INVALID_HANDLE_VALUE != hDevice)
{
    LPCSTR lpszTest = "Test";
    DWORD dwWritten = 0;
    ::WriteFile(hDevice, lpszTest, strlen(lpszTest), &dwWritten, NULL);
    ::CloseHandle(hDevice);
}



请注意,可能需要将设备名称更改为其他名称(_T(\\Device \\< name> ;)或长版本,如''usb#vid ...& pid ..& ...& CLSID'')。如果你得到了正确的名字,这应该可行。


Note that it may be necessary to change the device name to something else (_T("\\Device\\<name>") or the the long version like ''usb#vid...&pid..&...&CLSID''). If you got the correct name, this should work.


这篇关于再试一次 - 将ascii命令字符串写入虚拟打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆