Milind
Feb 23rd, 2001, 06:08 AM
Hi all,
VERY URGENT.
I got these code fro the forum..
""" Milind's comment and queries
======================
Public Sub Command1_Click()
Const ERROR_printer_ALREADY_EXISTS = 1802
'''' I want to add POstscript printer
Const printer_NAME = "Generic / Text Only"
Const PORT_NAME = "FILE:"
Const DRIVER_NAME = "Generic / Text Only"
'''' what is these print processor
Const PRINT_PROCESSOR = "winprint"
'''' on my SYSTEM there is NO winprint.dll ---will it work
Const DATA_TYPE = "TEXT"
Const DATA_FILE = "Txtonly.dll"
Const DRIVER_FILE = "Rasdd.dll"
Const CONFIG_FILE = "Rasddui.dll"
Const HELP_FILE = "Rasddui.hlp"
''' Iwant to add printer on local m/c win95 or winNT
Const ENVIRONMENT = "Windows NT x86"
''' which is basically a printer on network PC
Dim hpHandle As Long
Dim lError As Long
Dim lResult As Long
'''' the statement below gives errror at Max_Path
Dim sDriverBuf As String * Max_Path
'''' constant expression required
Dim sDriverPath As String
Dim lPathSize As Long
'On Error GoTo Addprintererror
' First we get the folder for the printer driver files
''''GetPrinterDriverDirectory 's 4th parameter (is it correct)
lResult = GetPrinterDriverDirectory(vbNullString, vbNullString, 1&, _
sDriverBuf, Max_Path, lPathSize)
'''' what about the 5th parameter Max_path
'''' can't go beyond these
If (lResult = 0) Then
errorhandler "Unable to retrieve the printer driver folder.", Err.LastDllError
End If
lResult = InStr(sDriverBuf, Chr$(0))
sDriverPath = Left$(sDriverBuf, lResult - 1)
If (Right$(sDriverPath, 1) <> "\") Then sDriverPath = sDriverPath & "\"
' Next we copy the required printer files to that folder
If (CopyFile(App.Path & "\" & DATA_FILE, sDriverPath & DATA_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Data).", Err.LastDllError
End If
If (Dir(sDriverPath & DATA_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & DATA_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & DRIVER_FILE, sDriverPath & DRIVER_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Driver).", Err.LastDllError
End If
If (Dir(sDriverPath & DRIVER_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & DRIVER_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & CONFIG_FILE, sDriverPath & CONFIG_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Config).", Err.LastDllError
End If
If (Dir(sDriverPath & CONFIG_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & CONFIG_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & HELP_FILE, sDriverPath & HELP_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Help).", Err.LastDllError
End If
If (Dir(sDriverPath & HELP_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & HELP_FILE, vbNormal
End If
'Add the printer Driver. This will configure the printer driver.
udtDriverInfo.cVersion = 2&
udtDriverInfo.pName = printer_NAME
udtDriverInfo.pEnvironment = ENVIRONMENT
udtDriverInfo.pDriverPath = sDriverPath & DRIVER_FILE
udtDriverInfo.pDataFile = sDriverPath & DATA_FILE
udtDriverInfo.pConfigFile = sDriverPath & CONFIG_FILE
udtDriverInfo.pHelpFile = sDriverPath & HELP_FILE
udtDriverInfo.pDependentFiles = DATA_FILE & Chr$(0) & _
DRIVER_FILE & Chr$(0) & _
CONFIG_FILE & Chr$(0) & _
HELP_FILE & Chr$(0) & Chr$(0)
udtDriverInfo.pMonitorName = vbNullString
udtDriverInfo.pDefaultDataType = DATA_TYPE
lResult = AddPrinterDriver(vbNullString, 3&, udtDriverInfo)
If (lResult = 0) Then
errorhandler "Unable to configure Generic printer driver.", Err.LastDllError
End If
' Now we can add the printer
udtPrinterInfo.pServerName = vbNullString
udtPrinterInfo.pPrinterName = printer_NAME
udtPrinterInfo.pPortName = PORT_NAME
udtPrinterInfo.pDriverName = DRIVER_NAME
udtPrinterInfo.pPrintProcessor = PRINT_PROCESSOR
udtPrinterInfo.pDatatype = DATA_TYPE
hpHandle = AddPrinter(vbNullString, 2&, udtPrinterInfo)
If (hpHandle) Then
ClosePrinter (hpHandle)
Else
lError = Err.LastDllError
If (lError <> ERROR_printer_ALREADY_EXISTS) Then
errorhandler "Unable to install Generic printer.", lError
End If
End If
End Sub
''''' Does every m/c have printerDriverDirectory
''''' what does winprint (print_processor) imply
'''' on my system I have winprint directory with .def ,.rc ,c ,.h files one each nothing else.
Can somebody help out..
Very Urgent.
Thanks in advance,
Milind.
VERY URGENT.
I got these code fro the forum..
""" Milind's comment and queries
======================
Public Sub Command1_Click()
Const ERROR_printer_ALREADY_EXISTS = 1802
'''' I want to add POstscript printer
Const printer_NAME = "Generic / Text Only"
Const PORT_NAME = "FILE:"
Const DRIVER_NAME = "Generic / Text Only"
'''' what is these print processor
Const PRINT_PROCESSOR = "winprint"
'''' on my SYSTEM there is NO winprint.dll ---will it work
Const DATA_TYPE = "TEXT"
Const DATA_FILE = "Txtonly.dll"
Const DRIVER_FILE = "Rasdd.dll"
Const CONFIG_FILE = "Rasddui.dll"
Const HELP_FILE = "Rasddui.hlp"
''' Iwant to add printer on local m/c win95 or winNT
Const ENVIRONMENT = "Windows NT x86"
''' which is basically a printer on network PC
Dim hpHandle As Long
Dim lError As Long
Dim lResult As Long
'''' the statement below gives errror at Max_Path
Dim sDriverBuf As String * Max_Path
'''' constant expression required
Dim sDriverPath As String
Dim lPathSize As Long
'On Error GoTo Addprintererror
' First we get the folder for the printer driver files
''''GetPrinterDriverDirectory 's 4th parameter (is it correct)
lResult = GetPrinterDriverDirectory(vbNullString, vbNullString, 1&, _
sDriverBuf, Max_Path, lPathSize)
'''' what about the 5th parameter Max_path
'''' can't go beyond these
If (lResult = 0) Then
errorhandler "Unable to retrieve the printer driver folder.", Err.LastDllError
End If
lResult = InStr(sDriverBuf, Chr$(0))
sDriverPath = Left$(sDriverBuf, lResult - 1)
If (Right$(sDriverPath, 1) <> "\") Then sDriverPath = sDriverPath & "\"
' Next we copy the required printer files to that folder
If (CopyFile(App.Path & "\" & DATA_FILE, sDriverPath & DATA_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Data).", Err.LastDllError
End If
If (Dir(sDriverPath & DATA_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & DATA_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & DRIVER_FILE, sDriverPath & DRIVER_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Driver).", Err.LastDllError
End If
If (Dir(sDriverPath & DRIVER_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & DRIVER_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & CONFIG_FILE, sDriverPath & CONFIG_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Config).", Err.LastDllError
End If
If (Dir(sDriverPath & CONFIG_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & CONFIG_FILE, vbNormal
End If
If (CopyFile(App.Path & "\" & HELP_FILE, sDriverPath & HELP_FILE, False) = 0) Then
errorhandler "Unable to copy the required printer driver files (Help).", Err.LastDllError
End If
If (Dir(sDriverPath & HELP_FILE, vbReadOnly) <> "") Then
SetAttr sDriverPath & HELP_FILE, vbNormal
End If
'Add the printer Driver. This will configure the printer driver.
udtDriverInfo.cVersion = 2&
udtDriverInfo.pName = printer_NAME
udtDriverInfo.pEnvironment = ENVIRONMENT
udtDriverInfo.pDriverPath = sDriverPath & DRIVER_FILE
udtDriverInfo.pDataFile = sDriverPath & DATA_FILE
udtDriverInfo.pConfigFile = sDriverPath & CONFIG_FILE
udtDriverInfo.pHelpFile = sDriverPath & HELP_FILE
udtDriverInfo.pDependentFiles = DATA_FILE & Chr$(0) & _
DRIVER_FILE & Chr$(0) & _
CONFIG_FILE & Chr$(0) & _
HELP_FILE & Chr$(0) & Chr$(0)
udtDriverInfo.pMonitorName = vbNullString
udtDriverInfo.pDefaultDataType = DATA_TYPE
lResult = AddPrinterDriver(vbNullString, 3&, udtDriverInfo)
If (lResult = 0) Then
errorhandler "Unable to configure Generic printer driver.", Err.LastDllError
End If
' Now we can add the printer
udtPrinterInfo.pServerName = vbNullString
udtPrinterInfo.pPrinterName = printer_NAME
udtPrinterInfo.pPortName = PORT_NAME
udtPrinterInfo.pDriverName = DRIVER_NAME
udtPrinterInfo.pPrintProcessor = PRINT_PROCESSOR
udtPrinterInfo.pDatatype = DATA_TYPE
hpHandle = AddPrinter(vbNullString, 2&, udtPrinterInfo)
If (hpHandle) Then
ClosePrinter (hpHandle)
Else
lError = Err.LastDllError
If (lError <> ERROR_printer_ALREADY_EXISTS) Then
errorhandler "Unable to install Generic printer.", lError
End If
End If
End Sub
''''' Does every m/c have printerDriverDirectory
''''' what does winprint (print_processor) imply
'''' on my system I have winprint directory with .def ,.rc ,c ,.h files one each nothing else.
Can somebody help out..
Very Urgent.
Thanks in advance,
Milind.