我试过使用汇编, MOV DX,$379; IN AL,DX; 但出现 Privileged instruction 警告错误。不知还有什么方法?
你试试能不能用API NT内核是禁止直接访问底层的
看一下这个吧: The following is an example of opening a printer and writing a raw string of data to the printer. Note that you must send the correct printer name, such as "HP LaserJet 5MP" for the function to succeed. You are also responsible for embedding any necessary control codes that the printer may require.uses WinSpool;procedure WriteRawStringToPrinter(PrinterName:String; S:String); var Handle: THandle; N: DWORD; DocInfo1: TDocInfo1; begin if not OpenPrinter(PChar(PrinterName), Handle, nil) then begin ShowMessage('error ' + IntToStr(GetLastError)); Exit; end; with DocInfo1 do begin pDocName := PChar('test doc'); pOutputFile := nil; pDataType := 'RAW'; end; StartDocPrinter(Handle, 1, @DocInfo1); StartPagePrinter(Handle); WritePrinter(Handle, PChar(S), Length(S), N); EndPagePrinter(Handle); EndDocPrinter(Handle); ClosePrinter(Handle); end;procedure TForm1.Button1Click(Sender: TObject); begin WriteRawStringToPrinter('HP', 'Test This'); end;最好是在DOS下采用C/C++直接写程序最好。
MOV DX,$379;
IN AL,DX;
但出现
Privileged instruction
警告错误。不知还有什么方法?
NT内核是禁止直接访问底层的
The following is an example of opening a printer and writing a raw
string of data to the printer. Note that you must send the correct
printer name, such as "HP LaserJet 5MP" for the function to succeed.
You are also responsible for embedding any necessary control codes
that the printer may require.uses WinSpool;procedure WriteRawStringToPrinter(PrinterName:String; S:String);
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
ShowMessage('error ' + IntToStr(GetLastError));
Exit;
end;
with DocInfo1 do begin
pDocName := PChar('test doc');
pOutputFile := nil;
pDataType := 'RAW'; end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
WriteRawStringToPrinter('HP', 'Test This');
end;最好是在DOS下采用C/C++直接写程序最好。
我现在不是不能打印,我是想取得打印机的状态,
另外,你的程序好像是要安装打印驱动的,我是想
直接接上计算机就可以发指令了,无需安装驱动。