473,545 Members | 289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

zebra Printer

Hello,

I am going to be using a Symbol WT4090 to scan items. I need to
printer a tag from the Zebra ql320 plus. I am trying to do this is
Visual basic 2005. Does anyone know and good site to find out how to
do this. I have looked everywhere i know with no luck. Thank you in
advance for your help.
Jun 27 '08 #1
9 10231
On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
Hello,

I am going to be using a Symbol WT4090 to scan items. I need to
printer a tag from the Zebra ql320 plus. I am trying to do this is
Visual basic 2005. Does anyone know and good site to find out how to
do this. *I have looked everywhere i know with no luck. Thank you in
advance for your help.
After you scaned an item you need to print it on an Printer?
Depends on how you can connect to the printer. If the printer is
connected to one PC you have to send Raw Bytes to the Printer. But
therefore you need to have one template written in ZPL (or what
language your printer 'speaks')
Jun 27 '08 #2
On 28 Apr., 15:08, ReneMarxis <rene.mar...@ya hoo.dewrote:
On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
Hello,
I am going to be using a Symbol WT4090 to scan items. I need to
printer a tag from the Zebra ql320 plus. I am trying to do this is
Visual basic 2005. Does anyone know and good site to find out how to
do this. *I have looked everywhere i know with no luck. Thank you in
advance for your help.

After you scaned an item you need to print it on an Printer?
Depends on how you can connect to the printer. If the printer is
connected to one PC you have to send Raw Bytes to the Printer. But
therefore you need to have one template written in ZPL (or what
language your printer 'speaks')
http://www.zebra.com/id/zebra/na/en/...us.4.tabs.html

You can use CPCL, EPL2, ZPL2 .... to print
Jun 27 '08 #3
On Apr 28, 9:11*am, ReneMarxis <rene.mar...@ya hoo.dewrote:
On 28 Apr., 15:08, ReneMarxis <rene.mar...@ya hoo.dewrote:
On 28 Apr., 14:56, id10t error <tubbz...@gmail .comwrote:
Hello,
I am going to be using a Symbol WT4090 to scan items. I need to
printer a tag from the Zebra ql320 plus. I am trying to do this is
Visual basic 2005. Does anyone know and good site to find out how to
do this. *I have looked everywhere i know with no luck. Thank you in
advance for your help.
After you scaned an item you need to print it on an Printer?
Depends on how you can connect to the printer. If the printer is
connected to one PC you have to send Raw Bytes to the Printer. But
therefore you need to have one template written in ZPL (or what
language your printer 'speaks')

http://www.zebra.com/id/zebra/na/en/...ters/mobile/ql...

You can use CPCL, EPL2, ZPL2 .... to print
It will be connected wireless over network. That is the problem I am
having. I am not sure how to communicate to it.
This is the code I have if it connect with a com port. I can print
with this code if the printer is connected to the com port

Dim Texxxt As String
Dim SA As SECURITY_ATTRIB UTES
Dim hPortP As IntPtr, outfile As FileStream
LPTPORT = "Com1"
Texxxt = Me.RichTextBox1 .Text
hPort = CreateFile(LPTP ORT, GENERIC_WRITE, FILE_SHARE_WRIT E,
SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
'Dim outfile As FileStream = File.Create(hPo rtP,
FileAccess.Writ e, False) 'Create FileStream using Handle
outfile = New FileStream(hPor tP, FileAccess.Writ e, False)
Dim fileWriter As New StreamWriter(ou tfile)
'fileWriter.Wri teLine("! 0 200 200 240 1")
'fileWriter.Wri teLine("Journal ")
'fileWriter.Wri teLine("VB 128 0 0 50 100 157 123456789")
'fileWriter.Wri teLine("T 7 0 24 171 Barcode Value is
123456789")
'fileWriter.Wri teLine("FORM")
'fileWriter.Wri teLine("PRINT")
Dim copies As String = 1
'fileWriter.Wri teLine("! 0 200 200 325 " & copies)
fileWriter.Writ eLine("! 0 200 200 200 " & copies)
fileWriter.Writ eLine("LABEL")
fileWriter.Writ eLine("CONTRAST 0")
fileWriter.Writ eLine("TONE 0")
fileWriter.Writ eLine("SPEED 3")
fileWriter.Writ eLine("PAGE-WIDTH 250")
fileWriter.Writ eLine("BAR-SENSE")
fileWriter.Writ eLine("COUNTRY USA")
fileWriter.Writ eLine(";// PAGE 000000000250032 5")
'Store Number in upperleft Corner
'fileWriter.Wri teLine("TEXT90 5 0 25 3 003")
fileWriter.Writ eLine("TEXT90 5 0 25 200 003")
'SKU in upper right Corner
fileWriter.Writ eLine("TEXT90 5 0 25 100 5580154")
''Prints barcode on second line
fileWriter.Writ eLine("VB 128 1 3 40 50 200 0005580154")
''Prints Long SKU on line 3
fileWriter.Writ eLine("TEXT90 0 2 100 200
0211-90979-3600-010-1000")
''Prints UPC on Line 4
fileWriter.Writ eLine("TEXT90 0 3 120 200 UPC-188371")
''Prints Date Code
fileWriter.Writ eLine("TEXT90 0 2 140 200 308")
''Prints Store Number
fileWriter.Writ eLine("TEXT90 5 0 160 200 009")
''Prints White Tag
fileWriter.Writ eLine("TEXT90 5 0 150 100 29.99")
''Prints Speical Name
fileWriter.Writ eLine("TEXT90 5 0 190 200 Store Special")
''Prints Red Tag
fileWriter.Writ eLine("TEXT90 5 1 210 150 24.99")
fileWriter.Writ eLine("CUT")
fileWriter.Writ eLine("FORM")
fileWriter.Writ eLine("PRINT")
fileWriter.Flus h()
fileWriter.Clos e()
outfile.Close()
retval = CloseHandle(hPo rt)
End Sub

Jun 27 '08 #4
I am using winspool.Drv to print to the printer. In this case i don't
care if the printer is on Network or not. It is configured on my
server-machine which does the printing.

I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
WritePrinter... . from that windows-library to send the Text to the
printer.

I am sorry i can't tell you how to connect directly to an network
printer. But probably there is some alike method on windows mobile
Jun 27 '08 #5
On Apr 28, 9:31*am, ReneMarxis <rene.mar...@ya hoo.dewrote:
I am using winspool.Drv to print to the printer. In this case i don't
care if the printer is on Network or not. It is configured on my
server-machine which does the printing.

I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
WritePrinter... . from that windows-library to send the Text to the
printer.

I am sorry i can't tell you how to connect directly to an network
printer. But probably there is some alike method on windows mobile
do you have any sample code i could look at?
Jun 27 '08 #6
On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
On Apr 28, 9:31*am, ReneMarxis <rene.mar...@ya hoo.dewrote:
I am using winspool.Drv to print to the printer. In this case i don't
care if the printer is on Network or not. It is configured on my
server-machine which does the printing.
I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
WritePrinter... . from that windows-library to send the Text to the
printer.
I am sorry i can't tell you how to connect directly to an network
printer. But probably there is some alike method on windows mobile

do you have any sample code i could look at?
'Option Explicit On
Option Strict Off

Imports System.IO
Imports System.Runtime. InteropServices

Public Class RawPrinterHelpe r
' Structure and API declarions:
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
Structure DOCINFOW
<MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
<MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
<MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
End Structure

'UP: Geändert wegen unbalanced stack fehlermeldung
<DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function OpenPrinter(ByV al src As String, ByRef
hPrinter As IntPtr, ByVal pd As Integer) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
Int32) As Boolean
End Function
Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
hPrinter As _
IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
cbBuf _
As Integer, ByRef pcbNeeded As Integer) As Boolean

' SendBytesToPrin ter()
' When the function is given a printer name and an unmanaged array
of
' bytes, the function sends those bytes to the print queue.
' Returns True on success or False on failure.
Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
Dim hPrinter As IntPtr ' The printer handle.
Dim dwError As Int32 ' Last error - in case there
was trouble.
Dim di As DOCINFOW = Nothing ' Describes your document
(name, port, data type).
Dim dwWritten As Int32 ' The number of bytes written
by WritePrinter().
Dim bSuccess As Boolean ' Your success code.

' Set up the DOCINFO structure.
With di
.pDocName = "My Visual Basic .NET RAW Document"
.pDataType = "RAW"
End With
' Assume failure unless you specifically succeed.
bSuccess = False
If OpenPrinter(szP rinterName, hPrinter, 0) Then

Dim ByteBuf As Integer
Dim BytesNeeded As Int32
Dim PrinterInfo2 As New PRINTER_INFO_2
Dim PrinterInfo() As Byte
Dim result As Boolean

'Determine the buffer size that is required to obtain the
printer information.
result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
'Display the error message that you receive when you call
the GetPrinter function,
'and then close the printer handle.
dwError = Marshal.GetLast Win32Error()
If dwError <ERROR_INSUFFIC IENT_BUFFER And _
dwError <0 Then
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If

ReDim PrinterInfo(Byt esNeeded)
ByteBuf = BytesNeeded

'Call the GetPrinter function to obtain the status.
result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
BytesNeeded)
'Check for any errors.
If Not result Then
'Get the error.
dwError = Marshal.GetLast Win32Error()
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If
PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
If PrinterInfo2.St atus <0 Then
Throw New MESPopupExcepti on("DCS-1032",
MESPopup.Meldun gsTypen.Fehler, szPrinterName,
GetPrinterStatu sText(PrinterIn fo2.Status))
Exit Function
End If

' Im Falle, dass der Drucker ohne Spooler konfiguriert
wurde,
' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
Rückmeldung vom Betriebssystem
' und die Methode EndDocPrinter bleibt hängen. Dazu wird
diese Methode mittels eines
' zusätzlichen Threads mit Timeout von 20s gestartet

' Um Übergabeparamet er an den Thread übergeben zu können,
wird ein Objekt der Klasse
' "PrinterThr ead" angelegt und die Property pHandle
gesetzt
Dim myPrinterThread Obj As New PrinterThread
myPrinterThread Obj.m_pHandle = hPrinter
myPrinterThread Obj.m_DocInfo = di
Dim myThread As System.Threadin g.Thread

myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.StartDocPri nter)
myThread.Start( )
Dim retBool As Boolean = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
bSuccess = myPrinterThread Obj.retVal

If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
' Write your printer-specific bytes to the printer.
If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
If bSuccess Then bSuccess = EndPagePrinter( hPrinter)
'If StartDocPrinter (hPrinter, 1, di) Then
' If StartPagePrinte r(hPrinter) Then
' ' Write your printer-specific bytes to the
printer.
' bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
' bSuccess = EndPagePrinter( hPrinter)
' End If

If bSuccess Then
myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.EndDocPrint er)
myThread.Start( )
retBool = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
End If

'bSuccess = EndDocPrinter(h Printer)
'End If

ClosePrinter(hP rinter)
End If
' If you did not succeed, GetLastError may give more
information
' about why not.
If bSuccess = False Then
dwError = Marshal.GetLast Win32Error()
Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
Const ERROR_INVALID_P RINTER_STATE As Int32 = 1906
Const ERROR_PRINTER_N OT_FOUND As Int32 = 3012

Select Case dwError
Case ERROR_INVALID_P RINTER_NAME
'DCS-1025 = Drucker {0} ist unter Windows nicht
bekannt!
Throw New MESPopupExcepti on("DCS-1025",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_INVALID_P RINTER_COMMAND
'DCS-1026 = Druckkommando {0} ist ungültig!
Throw New MESPopupExcepti on("DCS-1026",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_PRINTER_O UT_OF_PAPER
'DCS-1027 = Drucker {0} hat kein Papier!
Throw New MESPopupExcepti on("DCS-1027",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_INVALID_P RINTER_STATE
'DCS-1028 = Drucker {0} ist nicht bereit!
Throw New MESPopupExcepti on("DCS-1028",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_PRINTER_N OT_FOUND
'DCS-1029 = Drucker {0} nicht gefunden!
Throw New MESPopupExcepti on("DCS-1029",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case Else
'DCS-1030 = Unbekannter Fehler beim Ausdruck des
Etiketts! Fehlercode: {1}
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, dwError.ToStrin g)
End Select

End If
Return bSuccess
End Function ' SendBytesToPrin ter()

' SendFileToPrint er()
' When the function is given a file name and a printer name,
' the function reads the contents of the file and sends the
' contents to the printer.
' Presumes that the file contains printer-ready data.
' Shows how to use the SendBytesToPrin ter function.
' Returns True on success or False on failure.
Public Shared Function SendFileToPrint er(ByVal szPrinterName As
String, ByVal szFileName As String) As Boolean
' Open the file.
Dim fs As New FileStream(szFi leName, FileMode.Open)
' Create a BinaryReader on the file.
Dim br As New BinaryReader(fs )
' Dim an array of bytes large enough to hold the file's
contents.
Dim bytes(CInt(fs.L ength)) As Byte
Dim bSuccess As Boolean
' Your unmanaged pointer.
Dim pUnmanagedBytes As IntPtr

' Read the contents of the file into the array.
bytes = br.ReadBytes(CI nt(fs.Length))
' Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCo TaskMem(CInt(fs .Length))
' Copy the managed byte array into the unmanaged array.
Marshal.Copy(by tes, 0, pUnmanagedBytes , CInt(fs.Length) )
' Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrin ter(szPrinterNa me, pUnmanagedBytes ,
CInt(fs.Length) )
' Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoT askMem(pUnmanag edBytes)
Return bSuccess
End Function ' SendFileToPrint er()

' When the function is given a string and a printer name,
' the function sends the string to the printer as raw bytes.
Public Shared Sub SendStringToPri nter(ByVal szPrinterName As
String, ByVal szString As String)
Dim pBytes As IntPtr
Dim dwCount As Int32

szString = System.Text.Enc oding.Default.G etString( _

System.Text.Enc oding.GetEncodi ng(850).GetByte s(szString))

' How many characters are in the string?
dwCount = szString.Length ()
' Assume that the printer is expecting ANSI text, and then
convert
' the string to ANSI text.
pBytes = Marshal.StringT oCoTaskMemAnsi( szString)
' Send the converted ANSI string to the printer.
SendBytesToPrin ter(szPrinterNa me, pBytes, dwCount)
Marshal.FreeCoT askMem(pBytes)
End Sub
End Class

Module CheckPrinterSta tus

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)>
Structure PRINTER_INFO_2
Public pServerName As Integer
Public pPrinterName As Integer
Public pShareName As Integer
Public pPortName As Integer
Public pDriverName As Integer
Public pComment As Integer
Public pLocation As Integer
Public pDevMode As Integer
Public pSepFile As Integer
Public pPrintProcessor As Integer
Public pDatatype As Integer
Public pParameters As Integer
Public pSecurityDescri ptor As Integer
Public Attributes As Integer
Public Priority As Integer
Public DefaultPriority As Integer
Public StartTime As Integer
Public UntilTime As Integer
Public Status As Integer
Public cJobs As Integer
Public AveragePPM As Integer
End Structure

Public Function DatatoDeserial( ByVal datas() As Byte, ByVal
type_to_change As Type, _
ByVal NumJub As Long) As Object
'Returns the size of the JOB_INFO_2 structure
'HACK: Changed Long to integer
Dim Data_to_Size As Integer = Marshal.SizeOf( type_to_change)
If Data_to_Size datas.Length Then
Return Nothing
End If

Dim buffer As IntPtr = Marshal.AllocHG lobal(Data_to_S ize)
Dim startindex As Long
Dim i As Integer
For i = 0 To NumJub - 1
If i = 0 Then
startindex = 0
Else
startindex = startindex + Data_to_Size
End If
Next
'Copy data from the datas array to the unmanaged memory
pointer.
Marshal.Copy(da tas, startindex, buffer, Data_to_Size)

'Marshal data from the buffer pointer to a managed object.
Dim result_obj As Object = Marshal.PtrToSt ructure(buffer,
type_to_change)
'Free the memory that is allocated from the unmanaged memory.
Marshal.FreeHGl obal(buffer)
Return result_obj
End Function

'Define the printer status constants.
Public Const ERROR_INSUFFICI ENT_BUFFER As Integer = 122
Public Const PRINTER_STATUS_ BUSY As Integer = &H200
Public Const PRINTER_STATUS_ DOOR_OPEN As Integer = &H400000
Public Const PRINTER_STATUS_ ERROR As Integer = &H2
Public Const PRINTER_STATUS_ INITIALIZING As Integer = &H8000
Public Const PRINTER_STATUS_ IO_ACTIVE As Integer = &H100
Public Const PRINTER_STATUS_ MANUAL_FEED As Integer = &H20
Public Const PRINTER_STATUS_ NO_TONER As Integer = &H40000
Public Const PRINTER_STATUS_ NOT_AVAILABLE As Integer = &H1000
Public Const PRINTER_STATUS_ OFFLINE As Integer = &H80
Public Const PRINTER_STATUS_ OUT_OF_MEMORY As Integer = &H200000
Public Const PRINTER_STATUS_ OUTPUT_BIN_FULL As Integer = &H800
Public Const PRINTER_STATUS_ PAGE_PUNT As Integer = &H80000
Public Const PRINTER_STATUS_ PAPER_JAM As Integer = &H8
Public Const PRINTER_STATUS_ PAPER_OUT As Integer = &H10
Public Const PRINTER_STATUS_ PAPER_PROBLEM As Integer = &H40
Public Const PRINTER_STATUS_ PAUSED As Integer = &H1
Public Const PRINTER_STATUS_ PENDING_DELETIO N As Integer = &H4
Public Const PRINTER_STATUS_ PRINTING As Integer = &H400
Public Const PRINTER_STATUS_ PROCESSING As Integer = &H4000
Public Const PRINTER_STATUS_ TONER_LOW As Integer = &H20000
Public Const PRINTER_STATUS_ USER_INTERVENTI ON As Integer =
&H100000
Public Const PRINTER_STATUS_ WAITING As Integer = &H2000
Public Const PRINTER_STATUS_ WARMING_UP As Integer = &H10000

Public Function GetPrinterStatu sText(ByVal PI2Status As Long) As
String
Dim tempStr As String
If PI2Status = 0 Then ' Return the "Ready" status.
GetPrinterStatu sText = "Ready"
Else
tempStr = ""
'Determine the printer state.
If (PI2Status And PRINTER_STATUS_ BUSY) Then
tempStr = tempStr & "Busy"
End If
If (PI2Status And PRINTER_STATUS_ DOOR_OPEN) Then
tempStr = tempStr & "Printer Door Open"
End If
If (PI2Status And PRINTER_STATUS_ ERROR) Then
tempStr = tempStr & "Printer Error"
End If
If (PI2Status And PRINTER_STATUS_ INITIALIZING) Then
tempStr = tempStr & "Initializi ng"
End If
If (PI2Status And PRINTER_STATUS_ IO_ACTIVE) Then
tempStr = tempStr & "I/O Active"
End If
If (PI2Status And PRINTER_STATUS_ MANUAL_FEED) Then
tempStr = tempStr & "Manual Feed"
End If
If (PI2Status And PRINTER_STATUS_ NO_TONER) Then
tempStr = tempStr & "No Toner"
End If
If (PI2Status And PRINTER_STATUS_ NOT_AVAILABLE) Then
tempStr = tempStr & "Not Available"
End If
If (PI2Status And PRINTER_STATUS_ OFFLINE) Then
tempStr = tempStr & "Off Line"
End If
If (PI2Status And PRINTER_STATUS_ OUT_OF_MEMORY) Then
tempStr = tempStr & "Out of Memory"
End If
If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
tempStr = tempStr & "Output Bin Full"
End If
If (PI2Status And PRINTER_STATUS_ PAGE_PUNT) Then
tempStr = tempStr & "Page Punt"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_JAM) Then
tempStr = tempStr & "Paper Jam"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_OUT) Then
tempStr = tempStr & "Paper Out"
End If
If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
tempStr = tempStr & "Output Bin Full"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_PROBLEM) Then
tempStr = tempStr & "Page Problem"
End If
If (PI2Status And PRINTER_STATUS_ PAUSED) Then
tempStr = tempStr & "Paused"
End If
If (PI2Status And PRINTER_STATUS_ PENDING_DELETIO N) Then
tempStr = tempStr & "Pending Deletion"
End If
If (PI2Status And PRINTER_STATUS_ PRINTING) Then
tempStr = tempStr & "Printing"
End If
If (PI2Status And PRINTER_STATUS_ PROCESSING) Then
tempStr = tempStr & "Processing "
End If
If (PI2Status And PRINTER_STATUS_ TONER_LOW) Then
tempStr = tempStr & "Toner Low"
End If
If (PI2Status And PRINTER_STATUS_ USER_INTERVENTI ON) Then
tempStr = tempStr & "User Intervention"
End If
If (PI2Status And PRINTER_STATUS_ WAITING) Then
tempStr = tempStr & "Waiting"
End If
If (PI2Status And PRINTER_STATUS_ WARMING_UP) Then
tempStr = tempStr & "Warming Up"
End If
If Len(tempStr) = 0 Then
tempStr = "Unknown Status of " & PI2Status
End If
'Return the status.
GetPrinterStatu sText = tempStr
End If
End Function
End Module

Public Class PrinterThread
Public m_pHandle As System.IntPtr
Public m_DocInfo As RawPrinterHelpe r.DOCINFOW ' Describes
your document (name, port, data type).
Public retVal As Boolean

Public Sub EndDocPrinter()
retVal = RawPrinterHelpe r.EndDocPrinter (m_pHandle)
End Sub
Public Sub StartDocPrinter ()
retVal = RawPrinterHelpe r.StartDocPrint er(m_pHandle, 1,
m_DocInfo)
End Sub
End Class
Jun 27 '08 #7
Hi, just to chuck my views on this topic

We also have this problem, im sure the code works to the winspool.drv

but a more "noddy" approach we came up with, which also seems to work, we
scan and print to zebras on networks

Set up the printer on a server so that can print to it the same as below

execute a cmdprompt bur hidden, so the user has no idea that this is
happening then

1) delete a net use command to lpt6
2) create a net use mapping lpt6 to the printer (we've set that as an
configurable option in the application)
3) save the zpl codes to a text file
4) use a type command to print to LPT6


"ReneMarxis " <re*********@ya hoo.dewrote in message
news:a2******** *************** ***********@c65 g2000hsa.google groups.com...
On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
I am using winspool.Drv to print to the printer. In this case i don't
care if the printer is on Network or not. It is configured on my
server-machine which does the printing.
I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
WritePrinter... . from that windows-library to send the Text to the
printer.
I am sorry i can't tell you how to connect directly to an network
printer. But probably there is some alike method on windows mobile

do you have any sample code i could look at?
'Option Explicit On
Option Strict Off

Imports System.IO
Imports System.Runtime. InteropServices

Public Class RawPrinterHelpe r
' Structure and API declarions:
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
Structure DOCINFOW
<MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
<MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
<MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
End Structure

'UP: Geändert wegen unbalanced stack fehlermeldung
<DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function OpenPrinter(ByV al src As String, ByRef
hPrinter As IntPtr, ByVal pd As Integer) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
Int32) As Boolean
End Function
Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
hPrinter As _
IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
cbBuf _
As Integer, ByRef pcbNeeded As Integer) As Boolean

' SendBytesToPrin ter()
' When the function is given a printer name and an unmanaged array
of
' bytes, the function sends those bytes to the print queue.
' Returns True on success or False on failure.
Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
Dim hPrinter As IntPtr ' The printer handle.
Dim dwError As Int32 ' Last error - in case there
was trouble.
Dim di As DOCINFOW = Nothing ' Describes your document
(name, port, data type).
Dim dwWritten As Int32 ' The number of bytes written
by WritePrinter().
Dim bSuccess As Boolean ' Your success code.

' Set up the DOCINFO structure.
With di
.pDocName = "My Visual Basic .NET RAW Document"
.pDataType = "RAW"
End With
' Assume failure unless you specifically succeed.
bSuccess = False
If OpenPrinter(szP rinterName, hPrinter, 0) Then

Dim ByteBuf As Integer
Dim BytesNeeded As Int32
Dim PrinterInfo2 As New PRINTER_INFO_2
Dim PrinterInfo() As Byte
Dim result As Boolean

'Determine the buffer size that is required to obtain the
printer information.
result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
'Display the error message that you receive when you call
the GetPrinter function,
'and then close the printer handle.
dwError = Marshal.GetLast Win32Error()
If dwError <ERROR_INSUFFIC IENT_BUFFER And _
dwError <0 Then
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If

ReDim PrinterInfo(Byt esNeeded)
ByteBuf = BytesNeeded

'Call the GetPrinter function to obtain the status.
result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
BytesNeeded)
'Check for any errors.
If Not result Then
'Get the error.
dwError = Marshal.GetLast Win32Error()
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If
PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
If PrinterInfo2.St atus <0 Then
Throw New MESPopupExcepti on("DCS-1032",
MESPopup.Meldun gsTypen.Fehler, szPrinterName,
GetPrinterStatu sText(PrinterIn fo2.Status))
Exit Function
End If

' Im Falle, dass der Drucker ohne Spooler konfiguriert
wurde,
' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
Rückmeldung vom Betriebssystem
' und die Methode EndDocPrinter bleibt hängen. Dazu wird
diese Methode mittels eines
' zusätzlichen Threads mit Timeout von 20s gestartet

' Um Übergabeparamet er an den Thread übergeben zu können,
wird ein Objekt der Klasse
' "PrinterThr ead" angelegt und die Property pHandle
gesetzt
Dim myPrinterThread Obj As New PrinterThread
myPrinterThread Obj.m_pHandle = hPrinter
myPrinterThread Obj.m_DocInfo = di
Dim myThread As System.Threadin g.Thread

myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.StartDocPri nter)
myThread.Start( )
Dim retBool As Boolean = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
bSuccess = myPrinterThread Obj.retVal

If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
' Write your printer-specific bytes to the printer.
If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
If bSuccess Then bSuccess = EndPagePrinter( hPrinter)
'If StartDocPrinter (hPrinter, 1, di) Then
' If StartPagePrinte r(hPrinter) Then
' ' Write your printer-specific bytes to the
printer.
' bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
' bSuccess = EndPagePrinter( hPrinter)
' End If

If bSuccess Then
myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.EndDocPrint er)
myThread.Start( )
retBool = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
End If

'bSuccess = EndDocPrinter(h Printer)
'End If

ClosePrinter(hP rinter)
End If
' If you did not succeed, GetLastError may give more
information
' about why not.
If bSuccess = False Then
dwError = Marshal.GetLast Win32Error()
Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
Const ERROR_INVALID_P RINTER_STATE As Int32 = 1906
Const ERROR_PRINTER_N OT_FOUND As Int32 = 3012

Select Case dwError
Case ERROR_INVALID_P RINTER_NAME
'DCS-1025 = Drucker {0} ist unter Windows nicht
bekannt!
Throw New MESPopupExcepti on("DCS-1025",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_INVALID_P RINTER_COMMAND
'DCS-1026 = Druckkommando {0} ist ungültig!
Throw New MESPopupExcepti on("DCS-1026",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_PRINTER_O UT_OF_PAPER
'DCS-1027 = Drucker {0} hat kein Papier!
Throw New MESPopupExcepti on("DCS-1027",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_INVALID_P RINTER_STATE
'DCS-1028 = Drucker {0} ist nicht bereit!
Throw New MESPopupExcepti on("DCS-1028",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case ERROR_PRINTER_N OT_FOUND
'DCS-1029 = Drucker {0} nicht gefunden!
Throw New MESPopupExcepti on("DCS-1029",
MESPopup.Meldun gsTypen.Fehler, szPrinterName)
Case Else
'DCS-1030 = Unbekannter Fehler beim Ausdruck des
Etiketts! Fehlercode: {1}
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, dwError.ToStrin g)
End Select

End If
Return bSuccess
End Function ' SendBytesToPrin ter()

' SendFileToPrint er()
' When the function is given a file name and a printer name,
' the function reads the contents of the file and sends the
' contents to the printer.
' Presumes that the file contains printer-ready data.
' Shows how to use the SendBytesToPrin ter function.
' Returns True on success or False on failure.
Public Shared Function SendFileToPrint er(ByVal szPrinterName As
String, ByVal szFileName As String) As Boolean
' Open the file.
Dim fs As New FileStream(szFi leName, FileMode.Open)
' Create a BinaryReader on the file.
Dim br As New BinaryReader(fs )
' Dim an array of bytes large enough to hold the file's
contents.
Dim bytes(CInt(fs.L ength)) As Byte
Dim bSuccess As Boolean
' Your unmanaged pointer.
Dim pUnmanagedBytes As IntPtr

' Read the contents of the file into the array.
bytes = br.ReadBytes(CI nt(fs.Length))
' Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCo TaskMem(CInt(fs .Length))
' Copy the managed byte array into the unmanaged array.
Marshal.Copy(by tes, 0, pUnmanagedBytes , CInt(fs.Length) )
' Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrin ter(szPrinterNa me, pUnmanagedBytes ,
CInt(fs.Length) )
' Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoT askMem(pUnmanag edBytes)
Return bSuccess
End Function ' SendFileToPrint er()

' When the function is given a string and a printer name,
' the function sends the string to the printer as raw bytes.
Public Shared Sub SendStringToPri nter(ByVal szPrinterName As
String, ByVal szString As String)
Dim pBytes As IntPtr
Dim dwCount As Int32

szString = System.Text.Enc oding.Default.G etString( _

System.Text.Enc oding.GetEncodi ng(850).GetByte s(szString))

' How many characters are in the string?
dwCount = szString.Length ()
' Assume that the printer is expecting ANSI text, and then
convert
' the string to ANSI text.
pBytes = Marshal.StringT oCoTaskMemAnsi( szString)
' Send the converted ANSI string to the printer.
SendBytesToPrin ter(szPrinterNa me, pBytes, dwCount)
Marshal.FreeCoT askMem(pBytes)
End Sub
End Class

Module CheckPrinterSta tus

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Auto)>
Structure PRINTER_INFO_2
Public pServerName As Integer
Public pPrinterName As Integer
Public pShareName As Integer
Public pPortName As Integer
Public pDriverName As Integer
Public pComment As Integer
Public pLocation As Integer
Public pDevMode As Integer
Public pSepFile As Integer
Public pPrintProcessor As Integer
Public pDatatype As Integer
Public pParameters As Integer
Public pSecurityDescri ptor As Integer
Public Attributes As Integer
Public Priority As Integer
Public DefaultPriority As Integer
Public StartTime As Integer
Public UntilTime As Integer
Public Status As Integer
Public cJobs As Integer
Public AveragePPM As Integer
End Structure

Public Function DatatoDeserial( ByVal datas() As Byte, ByVal
type_to_change As Type, _
ByVal NumJub As Long) As Object
'Returns the size of the JOB_INFO_2 structure
'HACK: Changed Long to integer
Dim Data_to_Size As Integer = Marshal.SizeOf( type_to_change)
If Data_to_Size datas.Length Then
Return Nothing
End If

Dim buffer As IntPtr = Marshal.AllocHG lobal(Data_to_S ize)
Dim startindex As Long
Dim i As Integer
For i = 0 To NumJub - 1
If i = 0 Then
startindex = 0
Else
startindex = startindex + Data_to_Size
End If
Next
'Copy data from the datas array to the unmanaged memory
pointer.
Marshal.Copy(da tas, startindex, buffer, Data_to_Size)

'Marshal data from the buffer pointer to a managed object.
Dim result_obj As Object = Marshal.PtrToSt ructure(buffer,
type_to_change)
'Free the memory that is allocated from the unmanaged memory.
Marshal.FreeHGl obal(buffer)
Return result_obj
End Function

'Define the printer status constants.
Public Const ERROR_INSUFFICI ENT_BUFFER As Integer = 122
Public Const PRINTER_STATUS_ BUSY As Integer = &H200
Public Const PRINTER_STATUS_ DOOR_OPEN As Integer = &H400000
Public Const PRINTER_STATUS_ ERROR As Integer = &H2
Public Const PRINTER_STATUS_ INITIALIZING As Integer = &H8000
Public Const PRINTER_STATUS_ IO_ACTIVE As Integer = &H100
Public Const PRINTER_STATUS_ MANUAL_FEED As Integer = &H20
Public Const PRINTER_STATUS_ NO_TONER As Integer = &H40000
Public Const PRINTER_STATUS_ NOT_AVAILABLE As Integer = &H1000
Public Const PRINTER_STATUS_ OFFLINE As Integer = &H80
Public Const PRINTER_STATUS_ OUT_OF_MEMORY As Integer = &H200000
Public Const PRINTER_STATUS_ OUTPUT_BIN_FULL As Integer = &H800
Public Const PRINTER_STATUS_ PAGE_PUNT As Integer = &H80000
Public Const PRINTER_STATUS_ PAPER_JAM As Integer = &H8
Public Const PRINTER_STATUS_ PAPER_OUT As Integer = &H10
Public Const PRINTER_STATUS_ PAPER_PROBLEM As Integer = &H40
Public Const PRINTER_STATUS_ PAUSED As Integer = &H1
Public Const PRINTER_STATUS_ PENDING_DELETIO N As Integer = &H4
Public Const PRINTER_STATUS_ PRINTING As Integer = &H400
Public Const PRINTER_STATUS_ PROCESSING As Integer = &H4000
Public Const PRINTER_STATUS_ TONER_LOW As Integer = &H20000
Public Const PRINTER_STATUS_ USER_INTERVENTI ON As Integer =
&H100000
Public Const PRINTER_STATUS_ WAITING As Integer = &H2000
Public Const PRINTER_STATUS_ WARMING_UP As Integer = &H10000

Public Function GetPrinterStatu sText(ByVal PI2Status As Long) As
String
Dim tempStr As String
If PI2Status = 0 Then ' Return the "Ready" status.
GetPrinterStatu sText = "Ready"
Else
tempStr = ""
'Determine the printer state.
If (PI2Status And PRINTER_STATUS_ BUSY) Then
tempStr = tempStr & "Busy"
End If
If (PI2Status And PRINTER_STATUS_ DOOR_OPEN) Then
tempStr = tempStr & "Printer Door Open"
End If
If (PI2Status And PRINTER_STATUS_ ERROR) Then
tempStr = tempStr & "Printer Error"
End If
If (PI2Status And PRINTER_STATUS_ INITIALIZING) Then
tempStr = tempStr & "Initializi ng"
End If
If (PI2Status And PRINTER_STATUS_ IO_ACTIVE) Then
tempStr = tempStr & "I/O Active"
End If
If (PI2Status And PRINTER_STATUS_ MANUAL_FEED) Then
tempStr = tempStr & "Manual Feed"
End If
If (PI2Status And PRINTER_STATUS_ NO_TONER) Then
tempStr = tempStr & "No Toner"
End If
If (PI2Status And PRINTER_STATUS_ NOT_AVAILABLE) Then
tempStr = tempStr & "Not Available"
End If
If (PI2Status And PRINTER_STATUS_ OFFLINE) Then
tempStr = tempStr & "Off Line"
End If
If (PI2Status And PRINTER_STATUS_ OUT_OF_MEMORY) Then
tempStr = tempStr & "Out of Memory"
End If
If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
tempStr = tempStr & "Output Bin Full"
End If
If (PI2Status And PRINTER_STATUS_ PAGE_PUNT) Then
tempStr = tempStr & "Page Punt"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_JAM) Then
tempStr = tempStr & "Paper Jam"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_OUT) Then
tempStr = tempStr & "Paper Out"
End If
If (PI2Status And PRINTER_STATUS_ OUTPUT_BIN_FULL ) Then
tempStr = tempStr & "Output Bin Full"
End If
If (PI2Status And PRINTER_STATUS_ PAPER_PROBLEM) Then
tempStr = tempStr & "Page Problem"
End If
If (PI2Status And PRINTER_STATUS_ PAUSED) Then
tempStr = tempStr & "Paused"
End If
If (PI2Status And PRINTER_STATUS_ PENDING_DELETIO N) Then
tempStr = tempStr & "Pending Deletion"
End If
If (PI2Status And PRINTER_STATUS_ PRINTING) Then
tempStr = tempStr & "Printing"
End If
If (PI2Status And PRINTER_STATUS_ PROCESSING) Then
tempStr = tempStr & "Processing "
End If
If (PI2Status And PRINTER_STATUS_ TONER_LOW) Then
tempStr = tempStr & "Toner Low"
End If
If (PI2Status And PRINTER_STATUS_ USER_INTERVENTI ON) Then
tempStr = tempStr & "User Intervention"
End If
If (PI2Status And PRINTER_STATUS_ WAITING) Then
tempStr = tempStr & "Waiting"
End If
If (PI2Status And PRINTER_STATUS_ WARMING_UP) Then
tempStr = tempStr & "Warming Up"
End If
If Len(tempStr) = 0 Then
tempStr = "Unknown Status of " & PI2Status
End If
'Return the status.
GetPrinterStatu sText = tempStr
End If
End Function
End Module

Public Class PrinterThread
Public m_pHandle As System.IntPtr
Public m_DocInfo As RawPrinterHelpe r.DOCINFOW ' Describes
your document (name, port, data type).
Public retVal As Boolean

Public Sub EndDocPrinter()
retVal = RawPrinterHelpe r.EndDocPrinter (m_pHandle)
End Sub
Public Sub StartDocPrinter ()
retVal = RawPrinterHelpe r.StartDocPrint er(m_pHandle, 1,
m_DocInfo)
End Sub
End Class

Jun 27 '08 #8
On Jun 22, 6:06 am, "Simon Anderson"
<simon.ander... @newlinecomputi ng.comwrote:
Hi, just to chuck my views on this topic

We also have this problem, im sure the code works to the winspool.drv

but a more "noddy" approach we came up with, which also seems to work, we
scan and print to zebras on networks

Set up the printer on a server so that can print to it the same as below

execute a cmdprompt bur hidden, so the user has no idea that this is
happening then

1) delete a net use command to lpt6
2) create a net use mapping lpt6 to the printer (we've set that as an
configurable option in the application)
3) save the zpl codes to a text file
4) use a type command to print to LPT6

"ReneMarxis " <rene.mar...@ya hoo.dewrote in message

news:a2******** *************** ***********@c65 g2000hsa.google groups.com...
On 28 Apr., 15:52, id10t error <tubbz...@gmail .comwrote:
On Apr 28, 9:31 am, ReneMarxis <rene.mar...@ya hoo.dewrote:
I am using winspool.Drv to print to the printer. In this case i don't
care if the printer is on Network or not. It is configured on my
server-machine which does the printing.
I use OpenPrinterW, StartDocPrinter W, StartPagePrinte r,
WritePrinter... . from that windows-library to send the Text to the
printer.
I am sorry i can't tell you how to connect directly to an network
printer. But probably there is some alike method on windows mobile
do you have any sample code i could look at?

'Option Explicit On
Option Strict Off

Imports System.IO
Imports System.Runtime. InteropServices

Public Class RawPrinterHelpe r
' Structure and API declarions:
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Unicode)_
Structure DOCINFOW
<MarshalAs(Unma nagedType.LPWSt r)Public pDocName As String
<MarshalAs(Unma nagedType.LPWSt r)Public pOutputFile As String
<MarshalAs(Unma nagedType.LPWSt r)Public pDataType As String
End Structure

'UP: Geändert wegen unbalanced stack fehlermeldung
<DllImport("win spool.Drv", EntryPoint:="Op enPrinterW", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function OpenPrinter(ByV al src As String, ByRef
hPrinter As IntPtr, ByVal pd As Integer) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Cl osePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function ClosePrinter(By Val hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artDocPrinterW" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartDocPrinter (ByVal hPrinter As IntPtr,
ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dDocPrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndDocPrinter(B yVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="St artPagePrinter" , _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function StartPagePrinte r(ByVal hPrinter As IntPtr)
As Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="En dPagePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function EndPagePrinter( ByVal hPrinter As IntPtr) As
Boolean
End Function
<DllImport("win spool.Drv", EntryPoint:="Wr itePrinter", _
SetLastError:=T rue, CharSet:=CharSe t.Unicode, _
ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) _
Public Shared Function WritePrinter(By Val hPrinter As IntPtr,
ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As
Int32) As Boolean
End Function

Declare Auto Function GetPrinter Lib "winspool.d rv" (ByVal
hPrinter As _
IntPtr, ByVal Level As Integer, ByRef pPrinter As Byte, ByVal
cbBuf _
As Integer, ByRef pcbNeeded As Integer) As Boolean

' SendBytesToPrin ter()
' When the function is given a printer name and an unmanaged array
of
' bytes, the function sends those bytes to the print queue.
' Returns True on success or False on failure.
Public Shared Function SendBytesToPrin ter(ByVal szPrinterName As
String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
Dim hPrinter As IntPtr ' The printer handle.
Dim dwError As Int32 ' Last error - in case there
was trouble.
Dim di As DOCINFOW = Nothing ' Describes your document
(name, port, data type).
Dim dwWritten As Int32 ' The number of bytes written
by WritePrinter().
Dim bSuccess As Boolean ' Your success code.

' Set up the DOCINFO structure.
With di
.pDocName = "My Visual Basic .NET RAW Document"
.pDataType = "RAW"
End With
' Assume failure unless you specifically succeed.
bSuccess = False
If OpenPrinter(szP rinterName, hPrinter, 0) Then

Dim ByteBuf As Integer
Dim BytesNeeded As Int32
Dim PrinterInfo2 As New PRINTER_INFO_2
Dim PrinterInfo() As Byte
Dim result As Boolean

'Determine the buffer size that is required to obtain the
printer information.
result = GetPrinter(hPri nter, 2, 0&, 0, BytesNeeded)
'Display the error message that you receive when you call
the GetPrinter function,
'and then close the printer handle.
dwError = Marshal.GetLast Win32Error()
If dwError <ERROR_INSUFFIC IENT_BUFFER And _
dwError <0 Then
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If

ReDim PrinterInfo(Byt esNeeded)
ByteBuf = BytesNeeded

'Call the GetPrinter function to obtain the status.
result = GetPrinter(hPri nter, 2, PrinterInfo(0), ByteBuf,
BytesNeeded)
'Check for any errors.
If Not result Then
'Get the error.
dwError = Marshal.GetLast Win32Error()
Try
ClosePrinter(hP rinter)
Catch ex As Exception
End Try
Throw New MESPopupExcepti on("DCS-1031",
MESPopup.Meldun gsTypen.Fehler, szPrinterName, dwError.ToStrin g)
End If

PrinterInfo2 = CType(DatatoDes erial(PrinterIn fo,
GetType(PRINTER _INFO_2), 1), PRINTER_INFO_2)
If PrinterInfo2.St atus <0 Then
Throw New MESPopupExcepti on("DCS-1032",
MESPopup.Meldun gsTypen.Fehler, szPrinterName,
GetPrinterStatu sText(PrinterIn fo2.Status))
Exit Function
End If

' Im Falle, dass der Drucker ohne Spooler konfiguriert
wurde,
' erfolgt bei Druckerprobleme n (z.B. Netzwerk) keine
Rückmeldung vom Betriebssystem
' und die Methode EndDocPrinter bleibt hängen. Dazu wird
diese Methode mittels eines
' zusätzlichen Threads mit Timeout von 20s gestartet

' Um Übergabeparamet er an den Thread übergeben zu können,
wird ein Objekt der Klasse
' "PrinterThr ead" angelegt und die Property pHandle
gesetzt
Dim myPrinterThread Obj As New PrinterThread
myPrinterThread Obj.m_pHandle = hPrinter
myPrinterThread Obj.m_DocInfo = di
Dim myThread As System.Threadin g.Thread

myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.StartDocPri nter)
myThread.Start( )
Dim retBool As Boolean = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
bSuccess = myPrinterThread Obj.retVal

If bSuccess Then bSuccess = StartPagePrinte r(hPrinter)
' Write your printer-specific bytes to the printer.
If bSuccess Then bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
If bSuccess Then bSuccess = EndPagePrinter( hPrinter)

'If StartDocPrinter (hPrinter, 1, di) Then
' If StartPagePrinte r(hPrinter) Then
' ' Write your printer-specific bytes to the
printer.
' bSuccess = WritePrinter(hP rinter, pBytes,
dwCount, dwWritten)
' bSuccess = EndPagePrinter( hPrinter)
' End If

If bSuccess Then
myThread = New System.Threadin g.Thread(Addres sOf
myPrinterThread Obj.EndDocPrint er)
myThread.Start( )
retBool = myThread.Join(1 0000)
If Not retBool Then
myThread.Abort( )
Throw New MESPopupExcepti on("DCS-1030",
MESPopup.Meldun gsTypen.Fehler, "Timeout")
End If
End If

'bSuccess = EndDocPrinter(h Printer)
'End If

ClosePrinter(hP rinter)
End If
' If you did not succeed, GetLastError may give more
information
' about why not.
If bSuccess = False Then
dwError = Marshal.GetLast Win32Error()
Const ERROR_INVALID_P RINTER_NAME As Int32 = 1801
Const ERROR_INVALID_P RINTER_COMMAND As Int32 = 1803
Const ERROR_PRINTER_O UT_OF_PAPER As Int32 = 28
Const ERROR_INVALID_P RINTER_STATE As Int32 =
...

read more »
i've done this with zebras and eltrons included printers attached via
USB.
the sharing then mapping an unused LPT port is the trick.
Jun 27 '08 #9
id10t error wrote:
Hello,

I am going to be using a Symbol WT4090 to scan items. I need to
printer a tag from the Zebra ql320 plus. I am trying to do this is
Visual basic 2005. Does anyone know and good site to find out how to
do this. I have looked everywhere i know with no luck. Thank you in
advance for your help.
I while back I had to make one of our applications print on a Zebra
label printer (much larger than the sleak QL 320 Plus). What I did was
to produce the labels as a PDF document, and then let the user click on
the print icon in Adobe Reader to print the labels via the Windows
driver for the printer.

Using PDF might not be practical in your case, but there are Windows
drivers for the printer, so you should be able to print to it like any
other printer.

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15127
by: Twist Around | last post by:
We have to use a zebra printer to print some specialty labels. I was wondering if anyone had used python to output text to these. I know they use the Zebra Printing Language and before we got into that i was wondering if there was already a module that did this. Any info would be greatly appreciated. Thank You Christopher
0
2276
by: G.Esmeijer | last post by:
Friends, I would like to print to a Zebra 4M printer. This printer expects REAL text. Defining it at an IP address as a generic Text printer does not help. How do I send REAL text to that printer with C#. I seems to me that C# does not send real text but some graphical stuff to that printer. Stand printing in c# does not work In vb6 it...
6
8748
by: dzemo | last post by:
I have mentioned printer but how to print on him from code? I tried like POS printer copy .txt to LPT port but don't work. I tried print test page- still nothing. Any ideas? thx -- ----------------------------------------------------------------------------------------------------------------------- Dzemal Tipura (Dzemo) - MCP
13
10298
by: ATJaguarX | last post by:
I have a Zebra S500 and multiple S600 label printers. http://www.zebra.com/id/zebra/na/en/index/products/printers/industrial_commercial/s600.html They are currently being used in our legacy Foxpro application just fine. We are upgrading to ASP.NET and Crystal XI. I need to automate the process of printing these labels, so that when the...
2
24283
by: Crazyhorse | last post by:
Hi, I am trying to print labels to a zebra printer using the print document object in vb.net. Printing works fine to my local printer but with the Zebra, the data light indicator just flickers a couple of times and nothing else happens? Any help on this would be greatly appreciated Thanks
4
3172
by: =?Utf-8?B?UGF1bCBCdXp6YSwgb2xkc3RlciB1c2luZyBuZXcg | last post by:
I have developed a web-based inventory system for my estate jewelry business using ASP.Net 2.0 and Microsoft SQLServer. The inventory database is also the basis of my website (www.lookwhatifound.biz). I want to print jewelry tags on a local Zebra printer with the label consisting of fields from the web-based SQLServer database. I'm pretty...
0
2868
by: Charles Crawford | last post by:
Hi, This apparently is a common problem and I've yet to read a solution that actually works for my specific situation. I have a Zebra RW220 printer that I connect to via Bluetooth connection mapped to a serial port. The application I'm writing runs on a Windows Mobile 5 device, so there's no built in printer support and I have to use a...
0
3022
by: Raymond | last post by:
Hi All, Has any one work with FedEx Webservice with ASP? I am using ASP via SOAP to talk to FedEx Webservice, I have no problem printing the FedEx label with PNG or PDF, my problem is to print the raw Zebra printer file to the Zebra printer. I know that the web browser will not be able to do this, I need to create an ActiveX control.
2
6691
by: Flying Kite | last post by:
Hi All, I want to know how to print chinese characters on Zebra Printer, following code working fine with English string, but it's not working for Chinese string. It shows ASCII characters instead of Chinese characters, on my machine I installed language pack and currently set language as Chinese PRC but still it's not working. Option...
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.