Solved

Printer driver source example

Posted on 1998-08-31
5
460 Views
Last Modified: 2008-02-01
I need to create a printer driver to a generic text only printer. I would like a example source code and more inscructions ?
0
Comment
Question by:soares
5 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1432056
You will not be able to create a printer driver from VB...

However, you could create a DLL that would send print to a specified printer, which could the the Windows Generic Text Printer driver.
0
 
LVL 14

Expert Comment

by:waty
ID: 1432057
You can't create a printer driver.

Here, at work, we need to send postscript file to Xerox printer trough a generic text only driver, because we don't want interpretation. We had to modify a flag in the registry to do that, and print using API.

If it is that that you need, tell me, and I will post the code.

0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432058
If you want I can email you a generic text only printer driver.
Also tell me why do you need it.
I had some programs that needed a generic printer driver that are not common
and it works for me.

shayplace@hotmail.com
0
 

Author Comment

by:soares
ID: 1432059
I want configure two generic text only driver in same machine with diferent setting of paper and fonts. But when I change the configuration of the first the second if automatically changed too. And don't want it !!! I want two generic printer driver in the same machine configured with diferent settings

0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1432060
The purpose here is sending postscript file without any interpretation.

We have added a generic Printer Text driver and set the following key to in the registry :
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Printers\voltest -> DataType = "RAW"

voltest is our printer name

When we need to set particular seetings on the printer, we add it in the postscript file.

I will work within 2 or 3 weeks on job tickets to set directly the printers.

NB : We have here 3 Xerox Docutech 6135 and we print a lot each days.

I use the following code to send to Xerox Docutech printer :
Option Explicit

' constants for DEVMODE structure
Public Const CCHDEVICENAME = 32
Public Const CCHFORMNAME = 32
     
Public Type DEVMODE
   dmDeviceName As String * CCHDEVICENAME
   dmSpecVersion As Integer
   dmDriverVersion As Integer
   dmSize As Integer
   dmDriverExtra As Integer
   dmFields As Long
   dmOrientation As Integer
   dmPaperSize As Integer
   dmPaperLength As Integer
   dmPaperWidth As Integer
   dmScale As Integer
   dmCopies As Integer
   dmDefaultSource As Integer
   dmPrintQuality As Integer
   dmColor As Integer
   dmDuplex As Integer
   dmYResolution As Integer
   dmTTOption As Integer
   dmCollate As Integer
   dmFormName As String * CCHFORMNAME
   dmLogPixels As Integer
   dmBitsPerPel As Long
   dmPelsWidth As Long
   dmPelsHeight As Long
   dmDisplayFlags As Long
   dmDisplayFrequency As Long
   dmICMMethod As Long        ' // Windows 95 only
   dmICMIntent As Long        ' // Windows 95 only
   dmMediaType As Long        ' // Windows 95 only
   dmDitherType As Long       ' // Windows 95 only
   dmReserved1 As Long        ' // Windows 95 only
   dmReserved2 As Long        ' // Windows 95 only
End Type
             
Public Type PRINTER_DEFAULTS
   pDatatype As Long
   pDevMode As DEVMODE
   DesiredAccess As Long
End Type

' constants for DesiredAccess member of PRINTER_DEFAULTS
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
      PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

'
' Win32 API Calls
'
Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrn As Long, pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrn As Long, ByVal Level As Long, pDocInfo As DOC_INFO_1) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrn As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long
'
' Structure required by StartDocPrinter
'
Private Type DOC_INFO_1
   pDocName As String
   pOutputFile As String
   pDatatype As String
End Type

Public Sub SelectDefaultPrinter(Lst As ComboBox)
   Dim sRet As String
   Dim nRet As Integer
   Dim i As Integer
   '
   ' Look for default printer in WIN.INI
   '
   sRet = Space(255)
   nRet = GetProfileString("Windows", ByVal "device", "", _
                           sRet, Len(sRet))
   '
   ' Truncate default printer name.
   '
   If nRet Then
      sRet = UCase(Left(sRet, InStr(sRet, ",") - 1))
      '
      ' Cycle list looking for matching entry.
      '
      For i = 0 To Lst.ListCount
         If Left(UCase(Lst.List(i)), Len(sRet)) = sRet Then
            '
            ' Found it. Set index and bail.
            '
            Lst.ListIndex = i
            Exit For
         End If
      Next i
   End If
End Sub

Public Sub SpoolFile(sFile As String, PrnName As String, Optional AppName As String = "")
   Dim hPrn As Long
   Dim Buffer() As Byte
   Dim hFile As Integer
   Dim Written As Long
   Dim di As DOC_INFO_1
   Dim i As Long
   Const BufSize As Long = &H4000
   '
   ' Extract filename from passed spec, and build job name.
   ' Fill remainder of DOC_INFO_1 structure.
   '
   If InStr(sFile, "\") Then
      For i = Len(sFile) To 1 Step -1
         If Mid(sFile, i, 1) = "\" Then Exit For
         di.pDocName = Mid(sFile, i, 1) & di.pDocName
      Next i
   Else
      di.pDocName = sFile
   End If
   If Len(AppName) Then
      di.pDocName = AppName & ": " & di.pDocName
   End If
   di.pOutputFile = vbNullString
   di.pDatatype = "RAW"
   '
   ' Open printer for output to obtain handle.
   ' Set it up to begin recieving raw data.
   '
   
   ' set the PRINTER_DEFAULTS members
   Dim pd As PRINTER_DEFAULTS
   pd.pDatatype = 0&
   pd.DesiredAccess = PRINTER_ALL_ACCESS
         
   Debug.Print OpenPrinter(PrnName, hPrn, pd)
   Call StartDocPrinter(hPrn, 1, di)
   Call StartPagePrinter(hPrn)
   '
   ' Open file and pump it to the printer.
   '
   hFile = FreeFile
   Open sFile For Binary Access Read As hFile
      '
      ' Read in 16K buffers and spool.
      '
      ReDim Buffer(1 To BufSize) As Byte
      For i = 1 To LOF(hFile) \ BufSize
         Get #hFile, , Buffer
         Call WritePrinter(hPrn, Buffer(1), BufSize, Written)
      Next i
      '
      ' Get last chunk of file if it doesn't
      ' fit evenly into a 16K buffer.
      '
      If LOF(hFile) Mod BufSize Then
         ReDim Buffer(1 To (LOF(hFile) Mod BufSize)) As Byte
         Get #hFile, , Buffer
         Call WritePrinter(hPrn, Buffer(1), UBound(Buffer), Written)
      End If
   Close #hFile
   '
   ' Shut down spooling process.
   '
   Call EndPagePrinter(hPrn)
   Call EndDocPrinter(hPrn)
   Call ClosePrinter(hPrn)
End Sub

Public Function IsFile(SpecIn As String) As Boolean
   Dim Attr As Byte
   '
   ' Guard against bad SpecIn by ignoring errors.
   '
   On Error Resume Next
   '
   ' Get attribute of SpecIn.
   '
   Attr = GetAttr(SpecIn)
   If Err = 0 Then
      '
      ' No error, so something was found.
      ' If Directory attribute set, then not a file.
      '
      If (Attr And vbDirectory) = vbDirectory Then
         IsFile = False
      Else
         IsFile = True
      End If
   End If
End Function


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now