Printing to a USB Printer
Posted: Sat Dec 28, 2019 5:48 pm
I am totally new to PureBasic having not written a single program yet. I however have had many many years of Visual Basic 6. One of the things I frequently do is print to printers that print bar codes or tickets or special receipts that do not use the regular way of printing and are not based on a page model but rather a line model.
The following is code I use to send raw control codes to a Receipt or Ticket printer in VB6
Anyone game on assisting in translation?
From a search I see that it is a common problem. The person with the Zebra printer issue is at the very least one.
The following is code I use to send raw control codes to a Receipt or Ticket printer in VB6
Code: Select all
Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
Public Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long
Public Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Public Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type
Public Sub usbPrint(ByVal DataToBePrinted As String)
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sWrittenData As String
Dim MyDocInfo As DOCINFO
lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
If lReturn = 0 Then
MsgBox "Printer Error!" & Chr(10) & "Please Check Printer!", vbExclamation
Exit Sub
End If
MyDocInfo.pDocName = "Receipt"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
sWrittenData = DataToBePrinted
lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
End Sub
From a search I see that it is a common problem. The person with the Zebra printer issue is at the very least one.