新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#Lpt端口打印類的操作淺析
C#LPT端口打印類的操作是什么呢?首先讓我們看看什么是LPT端口(打印機專用)?LPT端口是一種增強了的雙向并行傳輸接口,在USB接口出現(xiàn)以前是掃描儀,打印機最常用的接口。***傳輸速度為1.5Mbps,設備容易安裝及使用,但是速度比較慢,下面是C#LPT端口打印類的操作具體實例:

創(chuàng)新互聯(lián)是一家專業(yè)的成都網(wǎng)站建設公司,我們專注成都網(wǎng)站制作、網(wǎng)站設計、外貿(mào)網(wǎng)站建設、網(wǎng)絡營銷、企業(yè)網(wǎng)站建設,賣友情鏈接,廣告投放為企業(yè)客戶提供一站式建站解決方案,能帶給客戶新的互聯(lián)網(wǎng)理念。從網(wǎng)站結(jié)構(gòu)的規(guī)劃UI設計到用戶體驗提高,創(chuàng)新互聯(lián)力求做到盡善盡美。
- using System;
- using System.Runtime.InteropServices;
- using System.IO;
- namespace printBarcode
- {
- ///
- /// LPTControl 的摘要說明,C#LPT端口打印類的操作
- ///
- 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端口打印類的操作的具體步驟就向你介紹到這里,希望對你了解C#LPT端口打印類有所幫助。
分享文章:C#Lpt端口打印類的操作淺析
文章URL:http://fisionsoft.com.cn/article/djsjdgg.html


咨詢
建站咨詢
