April 11th, 1999, 09:59 PM
I have a problem regarding the Use of Printer API's particularly AddPrinter and AddPrinterDriver..
Here's the Scenario
I'd like to a install a new printer programmatically but I need to create a new name for that printer. I tried configuring WIN.INI but I Have no luck.. If i rename the printer thru the printer dialog box.. the WIN.INI setting now points the winspooler.. I assumed that it maintains the names of installed printer objects to its drivers..
For example I wanted to install a barcode printer but not using its default Name..
I was successful in installing its driver thru AddPrinterDriver.. But i can't create a printer object out of the driver I installed by using AddPrinter..
I think I messed with its params.
Here's my code.. If u can give some suggestions:
Public Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Public Type DRIVER_INFO_3
cVersion As Long
pName As String ' QMS 810
pEnvironment As String ' Win32 x86
pDriverPath As String ' c:\drivers\pscript.dll
pDataFile As String ' c:\drivers\QMS810.PPD
pConfigFile As String ' c:\drivers\PSCRPTUI.DLL
pHelpFile As String ' c:\drivers\PSCRPTUI.HLP
pDependentFiles As String '
pMonitorName As String ' "PJL monitor"
pDefaultDataType As String ' "EMF"
End Type
Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As Any) As Long
Declare Function AddPrinterDriver Lib "winspool.drv" Alias "AddPrinterDriverA" (ByVal pName As String, ByVal Level As Long, pDriverInfo As Any) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Sub Command1_Click()
Dim gtypDriver_info As DRIVER_INFO_3
Dim gtypPrinter3_info As PRINTER_INFO_3
Dim gtypPrinter_info As PRINTER_INFO_2
Dim bolDriverResult As Long, bolPrinterResult As Long
' --- Printer Driver Settings
gtypDriver_info.cVersion = 768
gtypDriver_info.pName = "SATO CL 408"
gtypDriver_info.pEnvironment = "Windows 4.0"
gtypDriver_info.pDriverPath = "c:\windows\system\sato.drv"
gtypDriver_info.pDataFile = "c:\windows\system\sato.drv"
gtypDriver_info.pConfigFile = "c:\windows\system\sato.drv"
gtypDriver_info.pHelpFile = vbNullString
gtypDriver_info.pMonitorName = vbNullString
gtypDriver_info.pDefaultDataType = "RAW"
' ---- Printer Settings
gtypPrinter_info.pPrinterName = "Mon"
gtypPrinter_info.pShareName = vbNullString
gtypPrinter_info.pPortName = "LPT1:"
gtypPrinter_info.pDriverName = "SATO CL 408"
gtypPrinter_info.pComment = vbNullString
gtypPrinter_info.pLocation = vbNullString
gtypPrinter_info.pSepFile = vbNullString
gtypPrinter_info.pPrintProcessor = "WinPrint"
gtypPrinter_info.pDatatype = "RAW"
gtypPrinter_info.pParameters = vbNullString
gtypPrinter_info.Attributes = 64
gtypPrinter_info.Priority = 1
gtypPrinter_info.StartTime = 0
gtypPrinter_info.UntilTime = 0
bolDriverResult = AddPrinterDriver(vbNullString, 3, gtypDriver_info)
If bolDriverResult = 1 Then
bolPrinterResult = AddPrinter(vbNullString, 2, gtypPrinter_info)
If bolPrinterResult > 0 Then
MsgBox "Printer was Successfully Installed"
Else
MsgBox "Printer Not Installed"
End If
Else
MsgBox "Printer Driver Not Installed."
End If
ClosePrinter (bolPrinterResult)
End Sub
'---- END
A very big thanks...
Raymond Tejano
Here's the Scenario
I'd like to a install a new printer programmatically but I need to create a new name for that printer. I tried configuring WIN.INI but I Have no luck.. If i rename the printer thru the printer dialog box.. the WIN.INI setting now points the winspooler.. I assumed that it maintains the names of installed printer objects to its drivers..
For example I wanted to install a barcode printer but not using its default Name..
I was successful in installing its driver thru AddPrinterDriver.. But i can't create a printer object out of the driver I installed by using AddPrinter..
I think I messed with its params.
Here's my code.. If u can give some suggestions:
Public Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Public Type DRIVER_INFO_3
cVersion As Long
pName As String ' QMS 810
pEnvironment As String ' Win32 x86
pDriverPath As String ' c:\drivers\pscript.dll
pDataFile As String ' c:\drivers\QMS810.PPD
pConfigFile As String ' c:\drivers\PSCRPTUI.DLL
pHelpFile As String ' c:\drivers\PSCRPTUI.HLP
pDependentFiles As String '
pMonitorName As String ' "PJL monitor"
pDefaultDataType As String ' "EMF"
End Type
Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As Any) As Long
Declare Function AddPrinterDriver Lib "winspool.drv" Alias "AddPrinterDriverA" (ByVal pName As String, ByVal Level As Long, pDriverInfo As Any) As Long
Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Sub Command1_Click()
Dim gtypDriver_info As DRIVER_INFO_3
Dim gtypPrinter3_info As PRINTER_INFO_3
Dim gtypPrinter_info As PRINTER_INFO_2
Dim bolDriverResult As Long, bolPrinterResult As Long
' --- Printer Driver Settings
gtypDriver_info.cVersion = 768
gtypDriver_info.pName = "SATO CL 408"
gtypDriver_info.pEnvironment = "Windows 4.0"
gtypDriver_info.pDriverPath = "c:\windows\system\sato.drv"
gtypDriver_info.pDataFile = "c:\windows\system\sato.drv"
gtypDriver_info.pConfigFile = "c:\windows\system\sato.drv"
gtypDriver_info.pHelpFile = vbNullString
gtypDriver_info.pMonitorName = vbNullString
gtypDriver_info.pDefaultDataType = "RAW"
' ---- Printer Settings
gtypPrinter_info.pPrinterName = "Mon"
gtypPrinter_info.pShareName = vbNullString
gtypPrinter_info.pPortName = "LPT1:"
gtypPrinter_info.pDriverName = "SATO CL 408"
gtypPrinter_info.pComment = vbNullString
gtypPrinter_info.pLocation = vbNullString
gtypPrinter_info.pSepFile = vbNullString
gtypPrinter_info.pPrintProcessor = "WinPrint"
gtypPrinter_info.pDatatype = "RAW"
gtypPrinter_info.pParameters = vbNullString
gtypPrinter_info.Attributes = 64
gtypPrinter_info.Priority = 1
gtypPrinter_info.StartTime = 0
gtypPrinter_info.UntilTime = 0
bolDriverResult = AddPrinterDriver(vbNullString, 3, gtypDriver_info)
If bolDriverResult = 1 Then
bolPrinterResult = AddPrinter(vbNullString, 2, gtypPrinter_info)
If bolPrinterResult > 0 Then
MsgBox "Printer was Successfully Installed"
Else
MsgBox "Printer Not Installed"
End If
Else
MsgBox "Printer Driver Not Installed."
End If
ClosePrinter (bolPrinterResult)
End Sub
'---- END
A very big thanks...
Raymond Tejano