转载:C#Lpt端口打印类的操作浅析
2022/1/30 11:05:03
本文主要是介绍转载:C#Lpt端口打印类的操作浅析,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
转载:C#Lpt端口打印类的操作浅析 - 如.若 - 博客园 (cnblogs.com)
C#LPT端口打印类的操作是什么呢?首先让我们看看什么是LPT端口(打印机专用)?LPT端口是一种增强了的双向并行传输接口,在USB接口出现以前是扫描仪,打印机最常用的接口。最高传输速度为1.5Mbps,设备容易安装及使用,但是速度比较慢,下面是C#LPT端口打印类的操作具体实例:
/// <summary> /// LPTControl 的摘要说明,C#LPT端口打印类的操作 /// </summary> public class LPTControls { public LPTControls() { } [StructLayout(LayoutKind.Sequential)] private struct OVERLAPPED { int Internal; int InternalHigh; int Offset; int OffSetHigh; int hEvent; } [DllImport("kernel32.dll")] private static extern int CreateFile( string lpFileName, uint dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile ); [DllImport("kernel32.dll")] private static extern bool WriteFile( int hFile, byte[] lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, ref OVERLAPPED lpOverlapped ); [DllImport("kernel32.dll")] private static extern bool CloseHandle( int hObject ); //C#LPT端口打印类的操作 private int iHandle; public bool Open() { iHandle = CreateFile("lpt1", 0x40000000, 0, 0, 3, 0, 0); if (iHandle != -1) { return true; } else { return false; } } public bool Write(String Mystring) { if (iHandle != -1) { int i = 0; OVERLAPPED x = new OVERLAPPED(); byte[] mybyte = System.Text.Encoding.Default.GetBytes(Mystring); return WriteFile( iHandle, mybyte, mybyte.Length, ref i, ref x); } else { throw new Exception("端口未打开!"); } } public bool Close() { return CloseHandle(iHandle); } }
这篇关于转载:C#Lpt端口打印类的操作浅析的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-12-06使用Microsoft.Extensions.AI在.NET中生成嵌入向量
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#