打印机状态的读取,为何我的不行?

seeQe seeQe 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
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















...全文
评论 5
收藏 已收藏
分享
返回顶部
seeQe
VB基础类 7,788 成员 197,583 内容