C#中Lpt端口打印类怎么用

发布时间:2021-12-03 10:09:48 作者:小新
来源:亿速云 阅读:212

这篇文章主要介绍C#中Lpt端口打印类怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

C#LPT端口打印类的操作是什么呢?首先让我们看看什么是LPT端口(打印机专用)?LPT端口是一种增强了的双向并行传输接口,在USB接口出现以前是扫描仪,打印机最常用的接口。***传输速度为1.5Mbps,设备容易安装及使用,但是速度比较慢,下面是C#LPT端口打印类的操作具体实例:

using System;  using System.Runtime.InteropServices;  using System.IO;  namespace printBarcode  {   /// <summary>   /// LPTControl 的摘要说明,C#LPT端口打印类的操作   /// </summary>   public class LPTControl    {   public LPTControl()  {}   [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端口打印类的操作  }

以上是“C#中Lpt端口打印类怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. c#中抽象类怎么用
  2. C# 惠普打印机 打印

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

上一篇:如何通过实例学习Java对象的构造过程

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》