Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AddPrinterDriver API Call Fails?

Status
Not open for further replies.

DeFreitasM

IS-IT--Management
Dec 20, 2002
4
US
I Need to be able to add a new printer driver to 2000/XP and once that driver is added I need to Add the printer. I have AddPrinter working but, it fails every time I try to add a printer.... below is the Code I am using in my AddPrinterDriver Mod....
I am a Newbie @ API's So if you could please explain in you help it would be greatly appreciated...

Thanks,
Marcelo
Option Explicit

'******************************************************
' Adding Printer Drivers
'******************************************************

Public Type DRIVER_INFO_4
cVersion As Long ' DWORD cVersion
pName As Long ' String
pEnvironment As Long ' String
pDriverPath As Long ' String
pDataFile As Long ' String
pConfigFile As Long ' String
pHelpFile As Long
pDependentFiles As Long
pMonitorName As Long
pDefaultDataType As Long
pszzPreviousNames As Long
End Type

Public Declare Function AddPrinterDriver Lib "winspool.drv" Alias "AddPrinterDriverA" (ByVal pName As String, ByVal Level As Long, pDriverInfo As DRIVER_INFO_4) As Long
'*********************************************************


Sub MainDrv()
MsgBox "Driver Creation: " & APD("", "4")

End Sub

Function APD(strServer As String, _
strLeverl As String) As Boolean

Dim di2 As DRIVER_INFO_4
Dim dBuffer(1000) As Byte
Dim i
Dim strOS As String
Dim StrDrvPath As String
Dim StrpName As String
Dim StrpDataFile As String
Dim StrpHelpFile As String
Dim StrpDependentFiles As String
Dim StrpConfigFile As String

StrpName = "hp color LaserJet 4600 PCL 5c"
strOS = ""
StrDrvPath = "C:\Support\HP2\HPBF423G.DLL"
StrpDataFile = "c:\Support\hp2\HPBF423I.PMD"
StrpConfigFile = "c:\support\hp2\HPBF423E.DLL"
StrpHelpFile = "c:\support\hp2\HPBF423E.HLP"
StrpDependentFiles = "HPBF423G.DLL\0HPBF423E.DLL\0HPBF423I.PMD\0HPBF423E.HLP\0HPBAFD32.DLL\0HPBFTM32.DLL\0HPNRA.EXE\0HPBOID.EXE\0HPBPRO.EXE\0HPPAPML0.EXE\0HPBNRAC2.DLL\0HPBMIAPI.DLL\0HPBOIDPS.DLL\0HPBPROPS.DLL\0HPJCMN2U.DLL\0HPJIPX1U.DLL\0HPPAPTS0.DLL\0HPPASNM0.DLL\0HPPAPML0.DLL\0HPBMINI.DLL\0HPBF423G.HPI\0HPBCFGRE.DLL\0HPLJ4600.CFG\0HPCDMC32.DLL\0\0"

'*********************************************************************
' Initialise our buffer
'*********************************************************************

For i = 0 To UBound(dBuffer)
dBuffer(i) = 0
Next

'*********************************************************************
' Set the pointers to the string values in dBuffer
'*********************************************************************
di2.pName = AddString(StrpName, dBuffer)
di2.pEnvironment = AddString(strOS, dBuffer)
di2.pDriverPath = AddString(StrDrvPath, dBuffer)
di2.pDataFile = AddString(StrpDataFile, dBuffer)
di2.pConfigFile = AddString(StrpConfigFile, dBuffer)
di2.pHelpFile = AddString(StrpHelpFile, dBuffer)
di2.pDependentFiles = AddString(StrpDependentFiles, dBuffer)


'*********************************************************************
' Default all other values to 0 (NULL)
'*********************************************************************
di2.cVersion = 3
di2.pMonitorName = 0
di2.pDefaultDataType = 0
di2.pszzPreviousNames = 0

End Function
Private Function AddString(strString As String, ByRef dBuffer() As Byte) As Long

'*********************************************************************
' AddString copies a string into a Byte array and returns a long
' pointer to that string
'*********************************************************************

Dim lngEnd As Long

lngEnd = UBound(dBuffer) + 1
Do
lngEnd = lngEnd - 1
Loop While (dBuffer(lngEnd) = 0 And lngEnd > 0)
lngEnd = lngEnd + 2

lstrcpy VarPtr(dBuffer(0)) + lngEnd, strString

AddString = VarPtr(dBuffer(0)) + lngEnd
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top