1 class Printer
2 {
3 [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
4 private static extern SafeFileHandle CreateFile(string lpFileName, int dwDesiredAccess, int dwShareMode,
5 int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);
6
12 public static bool PrintLPT(string ZPL)
13 {
14 SafeFileHandle iHandle = CreateFile("LPT1", 0x40000000, 0, 0, 3, 0, 0);
15
16 if (!iHandle.IsInvalid)
17 {
18 FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
19 StreamWriter sw = new StreamWriter(fs, Encoding.Default);
20 sw.WriteLine(ZPL);
21 sw.Close();
22 fs.Close();
23 return true;
24 }
25 else
26 {
27 return false;
28 }
29 }
30 }