unit uRawDataPrint;
interface
uses
SysUtils,
printers,
winspool;
type
ERawDataToPrinterException =
class(
Exception );
procedure RawDataToPrinter( szPrinterName : PChar; lpData : PByte; dwCount : Word );
implementation
procedure RawDataToPrinter( szPrinterName : PChar; lpData : PByte; dwCount : Word );
var
hPrinter : THandle;
DocInfo : DOC_INFO_1;
dwJob : Word;
dwBytesWritten : Cardinal;
begin
Win32Check( OpenPrinter( szPrinterName, hPrinter,
nil ) );
try
DocInfo.pDocName := '
RAWJOB';
DocInfo.pOutputFile :=
nil;
DocInfo.pDatatype := '
RAW';
dwJob := StartDocPrinter( hPrinter, 1, @DocInfo );
if ( dwJob = 0 )
then
RaiseLastWin32Error;
try
Win32Check( StartPagePrinter( hPrinter ) );
try
Win32Check( WritePrinter( hPrinter, lpData, dwCount, dwBytesWritten ) );
if not( dwBytesWritten = dwCount )
then
raise ERawDataToPrinterException.Create( '
Nicht alle Bytes geschrieben' );
finally
Win32Check( EndPagePrinter( hPrinter ) );
end;
finally
Win32Check( EndDocPrinter( hPrinter ) );
end;
finally
Win32Check( ClosePrinter( hPrinter ) );
end;
end;
end.