How to print direclty to print server (zebra ZPL code) from vb6

The printer is a Zebra z4m, and I'm trying to print a file containing ZPL (zebra programming lang)

I have an existing print solution with the printer directly connected via LPT1, the code I'm using for this works perfectly:
-------working code----------
Open "c:\tropos\sdk\label" For Input As #1
Open "lpt1" For Output As #2
strTMP = Input(LOF(1), #1)
Print #2, strTMP
--------------------------------

The problem occurs when I want to put the printer on a network print server (D-Link DP-301p).

I've tried mapping lpt1 to the print server (net use lpt1: \\...etc) and using the same code as above but it fails (shows Error-printing in XP)

I've also tried using the printer object in vb i.e.:

Open "c:\tropos\sdk\label" For Input As #1
strTMP = Input(LOF(1), #1)
printer.print strtmp
printer.enddoc

but it still just comes up with an error straight away.

I've also tried setting the printer port to lpr printing as well as tcp/ip.

Now I'm truly stuck!
Any ideas anyone??

Jon
LVL 1
wheelibinAsked:
Who is Participating?
 
PocketMattConnect With a Mentor Commented:
Hi wheelibin

what happens if you open the command prompt and copy your printfile with the b - Param to the mapped port?
something like
copy c:\tropos\sdk\label lpt1 /b
if that works you could try if you can work it out with some api calls...
i always used api calls to control priters directly under windows xp.
such as these here..

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As OVERLAPPED) As Long

do you have special drivers for the printbox? you could try to install them instead of using the default tcp driver.
0
 
aruanaCommented:
Printing to LTP1 is not longer supported by XP and versions beyond.  Also, you are not able to map it to network queues as you have found out.
To send printer commands in windows driver, I now use JOE Hecht's rawprint.pas

There is a link to it here:
http://www.efg2.com/Lab/Library/Delphi/Printing/ 
look for item "Raw" printer access

It enables me to control the printer directly using windows drivers.
So, setup a windows printer driver (use generic type) and map it to the printserver queue.
Then send your printer commands to the driver using rawprint.
Remember to set the printer as default or use this command to set it,
    Printer.PrinterIndex:=n;
where n is the printer driver number.
0
 
wheelibinAuthor Commented:
PocketMatt:

Good shot!  That worked a treat, I may try and use the API calls too but for now the copying is good enough for me.

Cheers for the speedy answer :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.