代码如下:
Dim bPrinterInfo2() As Byte
Dim hPrinter As Long
Dim lResult As Long
Dim BytesNeeded As Long, BytesUsed As Long
Dim pd As PRINTER_DEFAULTS
Dim m_pi2 As PrinterInfo2If OpenPrinter(Printer.DeviceName, hPrinter, pd) = 0 Then Exit Function
Call GetPrinter(hPrinter, 2, 0, 0, BytesNeeded)
ReDim bPrinterInfo2(0 To BytesNeeded - 1) As Byte
lResult = GetPrinter(hPrinter, 2, bPrinterInfo2(0), BytesNeeded, BytesUsed)
Call CopyMemory(m_pi2.Attributes, bPrinterInfo2(52), 32) If m_pi2.Attributes And PRINTER_ATTRIBUTE_NETWORK > 0 Then '这个正确的
MsgBox "a network printer."
End If
Call CopyMemory(m_pi2.Status, bPrinterInfo2(72), 4) '这个是错误的以上代码中,能读到打印机的某些状态,但我始终无法读得它的"在线与否,缺纸"等状态
为什么? 请指点了.
其中:
Public Type PrinterInfo2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As Long 'DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As Long 'SECURITY_DESCRIPTOR
Attributes As Long '52
Priority As Long '56
DefaultPriority As Long '60
StartTime As Long '64
UntilTime As Long '68
Status As Long '72
cJobs As Long '76
AveragePPM As Long '80
End Type
Dim bPrinterInfo2() As Byte
Dim hPrinter As Long
Dim lResult As Long
Dim BytesNeeded As Long, BytesUsed As Long
Dim pd As PRINTER_DEFAULTS
Dim m_pi2 As PrinterInfo2If OpenPrinter(Printer.DeviceName, hPrinter, pd) = 0 Then Exit Function
Call GetPrinter(hPrinter, 2, 0, 0, BytesNeeded)
ReDim bPrinterInfo2(0 To BytesNeeded - 1) As Byte
lResult = GetPrinter(hPrinter, 2, bPrinterInfo2(0), BytesNeeded, BytesUsed)
Call CopyMemory(m_pi2.Attributes, bPrinterInfo2(52), 32) If m_pi2.Attributes And PRINTER_ATTRIBUTE_NETWORK > 0 Then '这个正确的
MsgBox "a network printer."
End If
Call CopyMemory(m_pi2.Status, bPrinterInfo2(72), 4) '这个是错误的以上代码中,能读到打印机的某些状态,但我始终无法读得它的"在线与否,缺纸"等状态
为什么? 请指点了.
其中:
Public Type PrinterInfo2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As Long 'DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As Long 'SECURITY_DESCRIPTOR
Attributes As Long '52
Priority As Long '56
DefaultPriority As Long '60
StartTime As Long '64
UntilTime As Long '68
Status As Long '72
cJobs As Long '76
AveragePPM As Long '80
End Type
http://www.mvps.org/vb/code/PrnInfo.zip