VB怎么检测打印机状态

 我来答
裙_我爱你4挙
2013-11-10
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
OptionExplicit Declare Function MapPhysToLin Lib "WinIo.dll" (ByVal PhysAddr AsLong, ByVal PhysSize AsLong, ByRef PhysMemHandle) AsLong Declare Function UnmapPhysicalMemory Lib "WinIo.dll" (ByVal PhysMemHandle, ByVal LinAddr) AsBoolean Declare Function GetPhysLong Lib "WinIo.dll" (ByVal PhysAddr AsLong, ByRef PhysVal AsLong) AsBoolean Declare Function SetPhysLong Lib "WinIo.dll" (ByVal PhysAddr AsLong, ByVal PhysVal AsLong) AsBoolean Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr AsInteger, ByRef PortVal AsLong, ByVal bSize AsByte) AsBoolean Declare Function SetPortVal Lib "WinIo.dll" (ByVal PortAddr AsInteger, ByVal PortVal AsLong, ByVal bSize AsByte) AsBoolean Declare Function InitializeWinIo Lib "WinIo.dll" () AsBoolean Declare Function ShutdownWinIo Lib "WinIo.dll" () AsBoolean Declare Function InstallWinIoDriver Lib "WinIo.dll" (ByVal DriverPath AsString, ByVal Mode AsInteger) AsBoolean Declare Function RemoveWinIoDriver Lib "WinIo.dll" () AsBooleanPublic IOStat AsBoolean'************************************************************ '* 函数名称:GetPrnStat * '* 功能:根据打印机的内存地址,检测打印机的目前工作状态 * '* 参数:lptport: 要检测的打印机的端口号,如LPT1: * '* 返回值:打印机的工作状态值。橹械腁PI函数InitializeWinIo和GetPortVal * '* 备注:检测的内存地址,是在打印端口所在的基地址上加1; * '* 作者:谷霖 * '* LPT1口的基地址为&H378;LPT2口的基地址为&H278 * '************************************************************PublicFunction GetPrnStat(ByVal LptPort AsString) AsLongDim PrnAddr AsLongOnErrorResumeNextIf IOStat =FalseThen IOStat = InitializeWinIo() If IOStat ThenIf UCase(LptPort) ="LPT1:"Then PrnAddr =&H379 ElseIf UCase(LptPort) ="LPT2:"Then PrnAddr =&H279 EndIf GetPortVal PrnAddr, GetPrnStat, 1Else GetPrnStat =&HFF EndIf GetPrnStat = GetPrnStat And&HF8 SelectCase GetPrnStat Case&H68, &H58, &H70 GetPrnStat =1'缺纸Case&H78 GetPrnStat =2'无联系Case&HD8 GetPrnStat =0'正常CaseElse GetPrnStat =3'异常EndSelectEnd Function'************************************************************************* '* 函数功能:检查打印机的状态主函数 * '* 输入参数:PrintName 要检测的打印机名称 * '* 输出参数:checkprinterr * '* 检查结果(0:正常 1:打印机缺纸 2:打印机无联系 3:打印机异常 * '* 4:没有安装打印机 5:打印机名称错误) * '*************************************************************************PublicFunction CheckPrintErr(ByVal PrintName AsString) AsLong'CheckPrintErr参数说明'0:没有错误'1:打印机无联系'2:打印机缺纸'3:没有安装打印机Dim printjieguo AsLongDim i AsLong, k AsLongOnErrorGoTo ErrCheckPrint If Printers.Count =0Then CheckPrintErr =4'没有安装打印机ExitFunctionEndIf'检测发票打印机是否可以联系For i =0To Printers.Count -1If (Printers(i).DeviceName = PrintName) Then k = k +1ExitForEndIfNextIf k =0Then'打印机名称错误 CheckPrintErr =5ExitFunctionEndIfSet Printer = Printers(i) CheckPrintErr = GetPrnStat(Printer.Port) ExitFunction ErrCheckPrint: CheckPrintErr =3ExitFunctionEnd Function
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
?>

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式