Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    [VB6] API di Windows - AddPrinterDriver

    Ho questo codice nel mio modulo:

    codice:
    'Value of Level Printer driver structure
    Global Const T_DRIVER_INFO_2 = 2 'DRIVER_INFO_2
    Global Const T_WIN_95_98_Me_NT4_UP = 3 'Windows 95/98/Me, Windows NT 4.0 or later: DRIVER_INFO_3
    Global Const T_WIN_2K_XP = 4 'Windows 2000 / XP: DRIVER_INFO_4
    Global Const T_WIN_ME_2K_XP = 6 'Windows Me, Windows 2000/XP: DRIVER_INFO_6
    
    Global Const ERROR_INVALID_PRINTER_NAME = 1801 'The printer name is invalid.
    Global Const ERROR_PRINTER_ALREADY_EXISTS = 1802 'The printer already exists.
    Global Const ERROR_INVALID_PRINTER_COMMAND = 1803 'The printer command is invalid.
    
    
    Public Type DRIVER_INFO_4
      cVersion As Long
      pName             As String
      pEnvironment      As String
      pDriverPath       As String
      pDataFile         As String
      pConfigFile       As String
      pHelpFile         As String
      pDependentFiles   As String
      pMonitorName      As String
      pDefaultDataType  As String
      pszzPreviousNames As String
    'cVersion
    '       Specifies the operating system version for which the driver
    '       was written. Currently it can only be the following. Value Meaning
    '       3 - Driver for Windows 2000/XP.
    'pName
    '       Pointer to a null-terminated string that specifies the name of the driver (for example, "QMS 810").
    'pEnvironment
    '       Pointer to a null-terminated string that specifies the environment for which the driver was written (for example, Windows NT x86, Windows NT R4000, Windows NT Alpha_AXP, or Windows 4.0).
    'pDriverPath
    '       Pointer to a null-terminated string that specifies a file name or full path and file name for the file that contains the device driver (for example, C:\DRIVERS\Pscript.dll).
    'pDataFile
    '       Pointer to a null-terminated string that specifies a file name or a full path and file name for the file that contains driver data (for example, C:\DRIVERS\Qms810.ppd).
    'pConfigFile
    '       Pointer to a null-terminated string that specifies a file name or a full path and file name for the device driver's configuration dynamic-link library (for example, C:\DRIVERS\Pscrptui.dll).
    'pHelpFile
    '       Pointer to a null-terminated string that specifies a file name or a full path and file name for the device driver's help file.
    'pDependentFiles
    '       Pointer to a null-terminated string that specifies the files the driver depends on. Each file name in the string is also terminated with a null (for example, Pscript.dll\0Qms810.PPD\0Pscrptui.dll\0Pspcriptui.hlp\0Pstest.txt\0\0).
    'pMonitorName
    '       Pointer to a null-terminated string that specifies a language monitor (for example, PJL monitor). This member can be NULL and should be specified only for printers capable of bidirectional communication.
    'pDefaultDataType
    '       Pointer to a null-terminated string that specifies the default data type of the print job (for example, EMF).
    'pszzPreviousNames
    '       Pointer to a null-terminated string that specifies any previous printer driver names that are compatible with this driver (for example, OldName1\0OldName2\0\0).
    End Type
    
    Type DRIVER_INFO_2
      cVersion As Long
      pName As String
      pEnvironment As String
      pDriverPath As String
      pDataFile As String
      pConfigFile As String
    'cVersion
    '   Specifies the operating system version for which the driver was written. It can be one of the following. Value Meaning
    '   0 - Driver for Windows 95/98/Me.
    '   1 - Driver for Windows NT 3.51.
    '   2 - Driver for Windows NT 4.0.
    '   3 - Driver for Windows 2000/XP.
    'pName
    '   Pointer to a null-terminated string that specifies the name of the driver (for example, "QMS 810").
    'pEnvironment
    '   Pointer to a null-terminated string that specifies the environment for which the driver was written (for example, "Windows NT x86", "Windows NT R4000", "Windows NT Alpha_AXP", or "Windows 4.0").
    'pDriverPath
    '   Pointer to null-terminated string that specifies a file name or full path and file name for the file that contains the device driver (for example, "c:\drivers\pscript.dll").
    'pDataFile
    '   Pointer to a null-terminated string that specifies a file name or a full path and file name for the file that contains driver data (for example, "c:\drivers\Qms810.ppd").
    'pConfigFile
    '   Pointer to a null-terminated string that specifies a file name or a full path and file name for the device-driver's configuration .dll (for example, "c:\drivers\Pscrptui.dll").
    End Type
    Type DRIVER_INFO_3
      cVersion As Long
      pName As String
      pEnvironment As String
      pDriverPath As String
      pDataFile As String
      pConfigFile As String
      pHelpFile As String
      pDependentFiles As String
      pMonitorName As String
      pDefaultDataType As String
    'cVersion
    '       Specifies the operating system version for which the driver was written. It can be one of the following. Value Meaning
    '       0 - Driver for Windows 95/98/Me.
    '       2 - Driver for Windows NT 4.0.
    '       3 - Driver for Windows 2000/XP.
    'pName
    '       Name of the driver (for example, "QMS 810").
    'pEnvironment
    '       for example, "Windows NT x86", "Windows NT R4000", "Windows NT Alpha_AXP", or "Windows 4.0").
    'pDriverPath
    '       file name or full path and file name for the file that contains
    '       the device driver (for example, "C:\DRIVERS\Pscript.dll").
    'pDataFile
    '       file name or a full path and file name for the file that contains
    '       driver data (for example, "C:\DRIVERS\Qms810.ppd").
    'pConfigFile
    '       file name or a full path and file name for the device driver's
    '       configuration dynamic-link library (for example, "C:\DRIVERS\Pscrptui.dll").
    'pHelpFile
    '       file name or a full path and file name for the device driver's
    '       help file.
    'pDependentFiles
    '       Pointer to a null-terminated string that specifies the files
    '       the driver is dependent on. Each file name in the string is also terminated with a null (for example, "Pscript.dll\0Qms810.PPD\0Pscrptui.dll\0Pspcriptui.hlp\0Pstest.txt\0\0").
    'pMonitorName
    '       Pointer to a null-terminated string that specifies a language
    '       monitor (for example, "PJL monitor").
    '       This member can be NULL and should be specified only for printers
    '       capable of bidirectional communication.
    'pDefaultDataType
    '       Pointer to a null-terminated string that specifies the default
    '       data type of the print job (for example, "EMF").
    
    End Type
    
    Public Declare Function AddPrinterDriver Lib "winspool.drv" Alias "AddPrinterDriverA" (ByVal pName As String, ByVal Level As Long, pDriverInfo As Any) As Long
    Public Declare Function GetPrinterDriver Lib "winspool.drv" Alias "GetPrinterDriverA" (ByVal hPrinter As Long, ByVal pEnvironment As String, ByVal Level As Long, pDriverInfo As Byte, ByVal cdBuf As Long, pcbNeeded As Long) As Long
    Public Declare Function GetPrinterDriverDirectory Lib "winspool.drv" _
           Alias "GetPrinterDriverDirectoryA" ( _
           ByVal pName As String, _
           ByVal pEnvironment As String, _
           ByVal Level As Long, _
           pDriverDirectory As Byte, _
           ByVal cdBuf As Long, _
           pcbNeeded As Long) As Long
    
    Public Declare Function GetLastError Lib "kernel32" () As Long
    Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Long, ByVal lpString2 As String) As Long
    
    
    Public Function AggiungiDriverXP()
        Dim bBuffer(1000) As Byte
        For i = 0 To UBound(bBuffer, 1)
            bBuffer(i) = 0
        Next i
        Dim DrvInfo As DRIVER_INFO_3
        With DrvInfo
            .cVersion = 1024
            .pDriverPath = "C:\gs\Driver\WinXP\PSCRIPT5.DLL"
            .pConfigFile = "C:\gs\Driver\WinXP\PS5UI.DLL"
            .pHelpFile = "C:\gs\Driver\WinXP\PSCRIPT.HLP"
            .pDataFile = "C:\gs\Driver\WinXP\HPCLJ5V2.PPD"
            .pDependentFiles = "C:\gs\Driver\WinXP\PSCRIPT.NTF"
            .pEnvironment = "Windows NT x86"
            .pName = "HP Color LaserJet 5/5M PS"
        End With
        x = AddPrinterDriver(vbNullChar, 3, DrvInfo)
        If x = 0 Then
            Select Case Err.LastDllError
            Case ERROR_INVALID_PRINTER_NAME
                MsgBox "Nome stampante non valido"
            Case 2
                MsgBox "Impossibile trovare il file"
            Case Else
                MsgBox Err.LastDllError
            End Select
        End If
        
    End Function
    
    Private Function AddString(strString As String, ByRef bBuffer() 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(bBuffer) + 1
       Do
          lngEnd = lngEnd - 1
       Loop While (bBuffer(lngEnd) = 0 And lngEnd > 0)
       lngEnd = lngEnd + 2
       lstrcpy VarPtr(bBuffer(0)) + lngEnd, strString
       AddString = VarPtr(bBuffer(0)) + lngEnd
    End Function
    se in un form richiamo la funzione aggiungidriverxp il programma gira gira poi mi da il messaggio "file non trovato" che è il codice di errore 2 (documentazione MSDN Library On-Line sito Microsoft:Vedi Qui ) i file esistono e sono nella posizione giusta e anche nella posizione di instazllazione che è

    C:\WINDOWS\system32\spool\drivers\w32x86\3

    ho provato anke a metterci questo percorso al posto di c:\gs...
    ma niente

    RAGA HELPATEMI PLS!!!!!
    anche solo se avete delle idee che non ho provato!!!

    Grazie Ciao
    *** Rachele TI AMO DA MORIRE!!! ***

  2. #2
    Se vi servono i File per provare è sufficente che installiate la stampante HP Color LaserJet 5/5M PS i cui driver li ha windows di suo...
    *** Rachele TI AMO DA MORIRE!!! ***

  3. #3
    ho provato anche a mandargli direttamente i puntatori agli indirizzi di memoria contenenti i dati ma l'errore rimane sempre il 2: File non Trovato.
    Ho anche sostituito il percorso con quello restituitomi dalla funzione GetPrinterDriverPath

    Come faccio a sapere di quale file si tratta? o che cosa sbaglio?
    *** Rachele TI AMO DA MORIRE!!! ***

  4. #4
    Nessuno è in grado di darmi una mano?
    *** Rachele TI AMO DA MORIRE!!! ***

  5. #5
    codice:
    Public Function AggiungiDriverXP()
        Dim bBuffer(1000) As Byte
        For i = 0 To UBound(bBuffer, 1)
            bBuffer(i) = 0
        Next i
        Dim DrvInfo As DRIVER_INFO_3
        With DrvInfo
            .cVersion = 1024
            .pDriverPath = "C:\gs\Driver\WinXP\PSCRIPT5.DLL"
            .pConfigFile = "C:\gs\Driver\WinXP\PS5UI.DLL"
            .pHelpFile = "C:\gs\Driver\WinXP\PSCRIPT.HLP"
            .pDataFile = "C:\gs\Driver\WinXP\HPCLJ5V2.PPD"
            .pDependentFiles = "C:\gs\Driver\WinXP\PSCRIPT.NTF"
            .pEnvironment = "Windows NT x86"
            .pName = "HP Color LaserJet 5/5M PS"
        End With
        x = AddPrinterDriver(vbNullChar, 3, DrvInfo)
        If x = 0 Then
            Select Case Err.LastDllError
            Case ERROR_INVALID_PRINTER_NAME
                MsgBox "Nome stampante non valido"
            Case 2
                MsgBox "Impossibile trovare il file"
            Case Else
                MsgBox Err.LastDllError
            End Select
        End If
        
    End Function
    ho modificato la riga x=AddPrinterDriver con
    codice:
    x = AddPrinterDriverEx(vbNullChar, 3, DrvInfo,1)
    e di conseguenza anche la definizione della funzione:
    codice:
    Public Declare Function AddPrinterDriverEx Lib "winspool.drv" Alias "AddPrinterDriverExA" (ByVal pName As String, ByVal Level As Long, pDriverInfo As Any, pFlags As Long) As Long
    Così facendo x mi restituisce 1 ma non installa i driver.

    esiste qualcuno in grado di aiutarmi?
    *** Rachele TI AMO DA MORIRE!!! ***

  6. #6
    :quote: UP
    *** Rachele TI AMO DA MORIRE!!! ***

  7. #7
    Originariamente inviato da Dardino
    :quote: UP
    *** Rachele TI AMO DA MORIRE!!! ***

  8. #8
    il problema ancora esiste
    *** Rachele TI AMO DA MORIRE!!! ***

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.