您的位置:首页 > 编程语言 > C#

c#开发一个zebar105sl的条码打印的程序

2009-02-06 21:09 381 查看
最近有个项目设及到要开发一个zebar105sl的条码打印的程序,以前没有接触过这类东西,不知道哪位牛哥能给些支持,在网上开到有高手提供的一段程序,内容如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Barcode_Print
{
class LPTControl
{
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
int Internal;
int InternalHigh;
int Offset; 字串6
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,
out int lpNumberOfBytesWritten,
out OVERLAPPED lpOverlapped
);

[DllImport("kernel32.dll")]
private static extern bool CloseHandle(
int hObject
);

private int iHandle;
public bool Open()
{
iHandle = CreateFile("lpt1", 0x40000000, 0, 0, 3, 0, 0);
字串3

if (iHandle != -1)
{
return true;
}
else
{
return false;
}

}

public bool Write(String Mystring)
{

if (iHandle != -1)
{
int i;
OVERLAPPED x;
byte[] mybyte = System.Text.Encoding.Default.GetBytes(Mystring);
return WriteFile(iHandle, mybyte, mybyte.Length, out i, out x);
}
else
{
throw new Exception("端口未打开!");
}
}

public bool Close()
{
return CloseHandle(iHandle);
}

}

但我不是很明白,我已经在自己的机器上装上了打印机的驱动测试页都没问题,现在不知到怎么把信息传给打印机,然后让打印机工作!有高手来一起讨论一下吗?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐