打印机状态的读取,为何我的不行?
代码如下:
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 PrinterInfo2
If 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 PrinterInfo2
If 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
...全文
相关推荐
获取打印机状态Delphi
用程序获取打印机状态 网络上的一些代码都不能成功 借鉴一下,查看API函数,一般是函数的参数使用不当造成 终于成功! 含源代码: Delphi6
c#获取打印机当前打印状态完整源码
公司业务需要,编写的可以获取当前打印机状态程序,例如缺纸,缺墨,暂停等,vs2103开发,首先获取本机所有打印机,然后指定特定打印机获取状态。
监控打印机状态 delphi
获取正在打印的列表信息,以及打印的状态,对卡纸等问题做出响应
C#实现获取打印机状态
C#调用API实现获取默认打印机当前状态。
C#获取打印机状态+API函数详解
C#获取打印机状态+API函数详解,有源码介绍,自己可以按照里面思路进行测试


VB基础类
