Delphi下的COM编程技术 - 2

大部分项目中有需要检测打印机的,那么我们用COM来实现:

(根据Delphi下的COM编程技术 - 1)

代码如下:

unit UprintMain; {$WARN SYMBOL_PLATFORM OFF} interface uses Windows, ActiveX, Classes, ComObj; type Iprinter= interface ['{14EC88EC-9F6F-449F-BEAC-3A3BF2837A58}']//这个ID是接口Iprinter//IID //function list function checkPrinterStatus(LPTPort:word):Byte;stdcall;//safecall end; TCprintSupport = class(TComObject,Iprinter) protected //Declare ICalculator methods here function checkPrinterStatus(LPTPort:word):Byte;stdcall;//safecall function testFunc(inputVal:Integer):integer;stdcall; //safecall end; const Class_CprintSupport: TGUID = '{6D380B4D-1B5C-4246-8587-F64C59158963}';//GUID implementation uses ComServ; function TCprintSupport.checkPrinterStatus(LPTPort:word):Byte; var statusLPT:Byte; checkLPT:Word; begin statusLPT:= 0; try if(LPTPort>=1)and(LPTPort<=3)then begin checkLPT:=LPTPort-1; asm mov dx,checkLPT; mov al,0; mov ah,2; int 17H; mov &statusLPT,ah; end; end; except Result:=0; end; Result:=statusLPT; end; initialization //初始化建立唯一的guid值的com对象 TComObjectFactory.Create(ComServer, TCprintSupport, Class_CprintSupport, 'CprintSupport', 'printer support plate01', ciMultiInstance, tmApartment); end.

主代码为端口检测:

asm
mov dx,checkLPT;
mov al,0;
mov ah,2;
int 17H;
mov &statusLPT,ah;
end;

工作原理:调用中断INT 17H,读取打印机的状态字节加以分析,即可得到其当前状态!

返回值有以下几种:
01H:超时
08H:I/O错误
10H:打印机未联机
20H:打印机缺纸
80H:打印机空

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值