Here is some sample c# code to print directly to a ZPL or EPL printer
using System;
using System.IO;
using System.Runtime. InteropServices ;
namespace CourierLib
{
/// <summary>
/// Summary description for ZPLPrint.
/// </summary>
public class ZPLPrint
{
public readonly int GENERIC_WRITE = 1073741824;
public readonly int OPEN_EXISTING = 3;
public readonly int FILE_SHARE_WRIT E = 2;
public string LPTPORT;
[DllImport("kern el32.dll", SetLastError=tr ue)]
public static extern IntPtr CreateFile(
string lpFileName,
EFileAccess dwDesiredAccess ,
EFileShare dwShareMode,
IntPtr lpSecurityAttri butes,
ECreationDispos ition dwCreationDispo sition,
EFileAttributes dwFlagsAndAttri butes,
IntPtr hTemplateFile);
[System.Runtime. InteropServices .DllImport("ker nel32",
EntryPoint="Clo seHan
dle")]
public static extern int CloseHandle(int hObject);
int retval;
[StructLayout(La youtKind.Sequen tial)]
public struct SECURITY_ATTRIB UTES
{
private int nLength;
private int lpSecurityDescr iptor;
private int bInheritHandle;
}
[Flags]
public enum EFileAccess : uint
{
GenericRead = 0x80000000,
GenericWrite = 0x40000000,
GenericExecute = 0x20000000,
GenericAll = 0x10000000,
}
[Flags]
public enum EFileShare : uint
{
None = 0x00000000,
Read = 0x00000001,
Write = 0x00000002,
Delete = 0x00000004,
}
public enum ECreationDispos ition : uint
{
New = 1,
CreateAlways = 2,
OpenExisting = 3,
OpenAlways = 4,
TruncateExistin g = 5,
}
[Flags]
public enum EFileAttributes : uint
{
Readonly = 0x00000001,
Hidden = 0x00000002,
System = 0x00000004,
Directory = 0x00000010,
Archive = 0x00000020,
Device = 0x00000040,
Normal = 0x00000080,
Temporary = 0x00000100,
SparseFile = 0x00000200,
ReparsePoint = 0x00000400,
Compressed = 0x00000800,
Offline= 0x00001000,
NotContentIndex ed = 0x00002000,
Encrypted = 0x00004000,
Write_Through = 0x80000000,
Overlapped = 0x40000000,
NoBuffering = 0x20000000,
RandomAccess = 0x10000000,
SequentialScan = 0x08000000,
DeleteOnClose = 0x04000000,
BackupSemantics = 0x02000000,
PosixSemantics = 0x01000000,
OpenReparsePoin t = 0x00200000,
OpenNoRecall = 0x00100000,
FirstPipeInstan ce = 0x00080000
}
public ZPLPrint()
{
//
// TODO: Add constructor logic here
//
}
public void print(string strPrnPath, string sText)
{
FileStream outFile;
IntPtr hPortP;
int hPort;
LPTPORT = strPrnPath;
hPortP = CreateFile(LPTP ORT, EFileAccess.Gen ericWrite,
EFileShare.Writ e,
IntPtr.Zero, ECreationDispos ition.OpenExist ing, EFileAttributes .Normal,
IntP
tr.Zero);
hPort = (int)hPortP;
outFile = new FileStream(hPor tP, FileAccess.Writ e, false);
StreamWriter fileWriter = new StreamWriter(ou tFile);
StreamReader fileReader = new
StreamReader("H :\\VSNet\\Couri erLib\\Parcel
ForceLabelDef.t xt");
fileWriter.Writ e("^XA^FO50,50^ A030,30^FD " + sText + "^FS");
fileWriter.Writ e(Formatting.Ch r(34));
fileWriter.Writ e("^FO50,100^A0 30,30^FD " + sText + "^FS^XZ");
fileWriter.Writ e(Formatting.Ch r(13));
fileWriter.Writ e(Formatting.Ch r(10));
fileWriter.Flus h();
fileWriter.Clos e();
outFile.Close() ;
retval = CloseHandle(hPo rt);
}
}
}
*** Sent via Developersdex
http://www.developersdex.com ***