Print file to LPT

I have some files on disk (.txt) and I need to send this file directly
to printer port, like in MS-DOS:
copy file1.txt lpt1
copy file2.txt lpt2
etc

I try a sample posted in this group some times ago, by Robson Meireles
in Out/23/98, but this code send the file to printer, open the spool
(show in task bar) and close the spool and nothing are printed. What
is wrong with this code?

procedure print(txtfile:string);
const
  BufSize = 16384;
type
  TDoc_Info_1 = record
    pDocName    : pChar;
    pOutputFile : pChar;
    pDataType   : pChar;
  end;
var
  Count : LongInt; //Cardinal;
  BytesWritten : LongInt; //Cardinal;
  hPrinter : THandle;
  Device : array[ 0..255 ] of char;
  Driver : array[ 0..255 ] of char;
  Port   : array[ 0..255 ] of char;
  hDeviceMode : THandle;
  DocInfo : TDoc_Info_1;
  f : file;
  Buffer : Pointer;
begin
if fileExists(txtfile) then
  begin
  try
  BytesWritten := 0;
  Printer.PrinterIndex := -1;
  Printer.GetPrinter( Device, Driver, Port, hDeviceMode );
  if not WinSpool.OpenPrinter( @Device, hPrinter, nil ) then exit;
  DocInfo.pDocName := spool';
  DocInfo.pOutputFile := nil;
  DocInfo.pDataType := 'RAW';
  if StartDocPrinter( hPrinter, {1}2, @DocInfo ) = 0 then
  begin
    WinSpool.ClosePrinter( hPrinter );
    Exit;
  end;
  if not StartPagePrinter( hPrinter ) then
  begin
    EndDocPrinter( hPrinter );
    WinSpool.ClosePrinter( hPrinter );
    Exit;
  end;
  System.AssignFile( f, txtfile );
  try
    Reset( f,1 );
    GetMem( Buffer, BufSize );
    while not EOF( f ) do
    begin
      BlockRead( f, Buffer^, BufSize, Count );
      if Count > 0 then
      begin
        //BytesWritten := count;
        if not WritePrinter( hPrinter, Buffer, Count, BytesWritten)
then
        begin
          EndPagePrinter( hPrinter );
          EndDocPrinter( hPrinter );
          WinSpool.ClosePrinter( hPrinter );
          FreeMem( Buffer, BufSize );
          Exit;
        end;
      end;
    end;
  finally
    WinSpool.EndPagePrinter( hPrinter );
    WinSpool.EndDocPrinter( hPrinter );
    WinSpool.ClosePrinter( hPrinter );
    FreeMem( Buffer, BufSize );
    System.CloseFile( f );
  end;
   except
     showmessage('Can't send file ['+
                  txtfile + '] to standard printer');
end;
end
else
   showmessage('file ['+
                txtfile + '] doesn't exists');
end;

=================
Thanks in advance.

Hrcules Russano
HRsft - "Simples, mas funciona"
S?o Gon?alo - RJ - Brasil

Remove 'nospam' from my email address to contact me.