borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2013 Andrea Tincaniborder

AndreaVB Home | Forum | News | Code Database Home | Search Database | View Latest Codes
Submit your Code | Register | HOWTO Submit a File

Code Database » Printing » How to print directly to the printer port
File Info
Version : 1.0.0
Support Topic : Click Here (0 comments)
Demo : N/A
Screenshot : N/A
Post Date : Apr 24, 2004
Last Edit Date : Apr 24, 2004
Language Version : VB6
Current Rating : 20 Votes; 5.00 Avg
Author Info
Author Name : skrtvm
Author Files Count : 1
% of Files by Author : 0.6757%
Private Msg : Login First!
Email : Login First!
Code Description
This is Visual Basic Program can be used to print directly to the printer port.

It is very fast!

Most Probably can be used Super Markets for customer satisfcation. They don't have to wait for the their bills.
Download Info
Download File : Click to Download!
Total Downloads : 9050
FileSize: 1.75 KB
FileType: TXT file
User Feedback
Rate This Code :
VB Code
#If Win32 Then
Public Type DOC_INFO_1
    pDocName As String
    pOutputFile As String
    pDatatype As String
End Type

#End If

#If Win32 Then
Public Declare Function OpenPrinter& Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) ' Third param changed to long
Public Declare Function StartDocPrinter& Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1)
Public Declare Function StartPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
Public Declare Function WritePrinter& Lib "winspool.drv" (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long)
Public Declare Function EndDocPrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
Public Declare Function EndPagePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
Public Declare Function ClosePrinter& Lib "winspool.drv" (ByVal hPrinter As Long)
#End If

Public Function ToPrinter(ByVal PrnData As String, ByVal PrinterDeviceName As String)

    Dim hPrinter&
    Dim jobid&
    Dim res&
    Dim written&
    Dim printdata$
    Dim docinfo As DOC_INFO_1
    res& = OpenPrinter(PrinterDeviceName, hPrinter, 0)
    If res = 0 Then
        MsgBox "Unable to open the printer"
        Exit Function
    End If
    docinfo.pDocName = "MyDoc"
    docinfo.pOutputFile = vbNullString
    docinfo.pDatatype = vbNullString
    jobid = StartDocPrinter(hPrinter, 1, docinfo)
    Call StartPagePrinter(hPrinter)
    printdata$ = PrnData & vbLineFeed
    Call WritePrinter(hPrinter, ByVal printdata$, Len(printdata$), written)
    Call EndPagePrinter(hPrinter)
    Call EndDocPrinter(hPrinter)
    Call ClosePrinter(hPrinter) ' Close when done

End Function

borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2013 Andrea Tincaniborder