VB6打印模块适用于Win98但不适用于Win7

时间:2015-01-14 12:18:30

标签: vb6

VB6打印模块适用于Win98但不适用于Win7。这部分文本可能有问题请给我解决方案。提前谢谢。


    Function NSPrintFile(PrinterName As String, FileToPrint As String, delAfterPrint As Long) As Long
    Dim I As Long
    Dim Success As Long, phPrinter As Long, Level As Long
    Dim cdBuf As Long, pcbNeeded As Long, JobId As Long
    Dim pPrinterName As String, strJobId As String, strSpoolFile As String
    Dim pDefault As PRINTER_DEFAULTS
    Dim pData As ADDJOB_INFO_1, StartPos As Integer, tmpStartPos As Integer

    pPrinterName = Printer.DeviceName
    Success = OpenPrinter(pPrinterName, phPrinter, pDefault)
    If Success <> 1 Then
        MsgBox "No Printers are installed or Cannot access the Printer !", vbExclamation, "NSPrint"
        NSPrintFile = False
        Exit Function
    End If
    Level = 1
    cdBuf = 64
    pcbNeeded = 0
    pData.Path = String(64, " ")
    Success = AddJob(phPrinter, Level, pData, cdBuf, pcbNeeded)
    If Success <> 1 Then
        MsgBox "Cannot assign JobID !", vbExclamation, "NSPrint"
        NSPrintFile = False
        Exit Function
    End If

    strJobId = Left(pData.Path, 4)
    JobId = Val(Asc(Mid(strJobId, 1, 1))) * 2 ^ 0
    JobId = JobId + Val(Asc(Mid(strJobId, 2, 1))) * 2 ^ 8
    JobId = JobId + Val(Asc(Mid(strJobId, 3, 1))) * 2 ^ 16
    JobId = JobId + Val(Asc(Mid(strJobId, 4, 1))) * 2 ^ 24

    tmpStartPos = 0
    Do Until tmpStartPos = 0 And StartPos <> 0
        tmpStartPos = tmpStartPos + 1
        tmpStartPos = InStr(tmpStartPos, pData.Path, "C:\")
        If tmpStartPos = 0 Then Exit Do
        StartPos = tmpStartPos
    Loop

    strSpoolFile = Mid(pData.Path, StartPos)
'    For i = 5 To 64
'        If Asc(Mid(pData.Path, i, 1)) <> 0 Then
'            strSpoolFile = strSpoolFile & Mid(pData.Path, i, 1)
'        End If
'    Next
    On Error Resume Next
    FileCopy FileToPrint, strSpoolFile
    If Err.Number <> 0 Then
        MsgBox Err.Number & " : " & Err.Description, vbExclamation, "NSPrint"
        NSPrintFile = False
        Exit Function
    End If
    Success = ScheduleJob(phPrinter, JobId)
    If Success <> 1 Then
        MsgBox "Cannot Spool the Printer JobID !", vbExclamation, "NSPrint"
        NSPrintFile = False
        Exit Function
    End If

    Success = ClosePrinter(phPrinter)
    If Success <> 1 Then
        MsgBox "Cannot close the Printer !", vbExclamation, "NSPrint"
        NSPrintFile = False
        Exit Function
    End If
    If delAfterPrint = True Then Kill FileToPrint
    NSPrintFile = True
End Function

注意:错误消息是“无法分配JobID!”

(这是用于调用打印功能的完整代码。相同的代码适用于Win98,但Win7失败。请给我一个解决方案。)

0 个答案:

没有答案