我想将数据发送到 LPT1 上的打印机,我正在尝试这样做,但我的 CreateFile 返回 -1(系统找不到指定的文件。来自 HRESULT:0x80070002 的异常)。如何打开LPT1端口并将数据发送到?我在 XP 上尝试这个,然后在 win7 64 位中尝试,因为从我读过的内容来看,在 win7 64 位中使用 LPT 有点问题,或者我应该说 64 位问题:)
PS:由于这是我今年的第一篇文章:祝大家新年快乐。
您可以尝试以下方法。适用于文本模式。
“净份额”显示以下内容:
Share name Resource Remark
-------------------------------------------------------------------------------
IPC$ Remote IPC
D$ D:\ Default share
print$ C:\WINDOWS\system32\spool\drivers
Printer Drivers
wwwroot$ c:\inetpub\wwwroot Used for file share access to web
C$ C:\ Default share
ADMIN$ C:\WINDOWS Remote Admin
SharedDocs C:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS
Printer2 IP_192.168.115.227 Spooled HP LaserJet 2200 Series PS (MS)
TEST LPT1: Spooled Microsoft XPS Document Writer
The command completed successfully.
这是代码
using System;
using System.IO;
namespace SimplePrinting
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class SimplePrinting
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string printingTaskFileName = Path.GetTempFileName(); // file in %temp%
System.IO.FileStream printingTaskFile;
System.IO.StreamWriter printingTaskStream;
printingTaskFile = new System.IO.FileStream(printingTaskFileName, FileMode.Append);
printingTaskStream = new System.IO.StreamWriter(printingTaskFile, System.Text.Encoding.Default);
printingTaskStream.Write("some content here");
printingTaskStream.Flush();
printingTaskStream.Close();
File.Copy(printingTaskFileName, @"\\127.0.0.1\TEST", true); // also can be \\127.0.0.1\PNT5 or smth like that
File.Delete(printingTaskFileName);
}
}
}