- 17
- 0
- 约3.99千字
- 约 3页
- 2023-06-09 发布于山东
- 举报
C#控制打印机(直接发送打印机命令到打印机)--第1页
C#控制打印机(直接发送打印机命令到打印
机)
一个打印机控制类,很有用的,其中使用了windows api 控制lpt 端口,对条码打印机的控制
法如下:将打印机的命令写到一个文件里,再使用之。
*******************************************************************************
*******************************************************
//代码:
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace LPTControls
{
public class LPTControls
{
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
int Internal;
intInternalHigh;
int Offset;
intOffSetHigh;
inthEvent;
}
[DllImport(kernel32.dll)]
private static extern intCreateFile(string lpFileName, uintdwDesiredAccess, intdwShareMode,
intlpSecurityAttributes, intdwCreationDisposition, intdwFlagsAndAttributes, inthTemplateFile);
[DllImport(kernel32.dll)]
private static extern boolWriteFile(inthFile, byte[] lpBuffer, intnNumberOfBytesToWriter,
out intlpNumberOfBytesWriten, out OVERLAPPED lpOverLapped);
[DllImport(kernel32.dll)]
private static extern boolCloseHandle(inthObject);
privateintiHandle;
//打开LP 端口
public bool Open()
{
C#控制打印机(直接发送打印机命令到打印机)--第1页
C#控制打印机(直接发送打印机命令到打印机)--第2页
iHandle = CreateFile(lpt1, 0 0, 0, 3, 0, 0);
原创力文档

文档评论(0)