Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Oct : Problem printing ascii file

www.cryer.info
Managed Newsgroup Archive

Problem printing ascii file

Subject:Problem printing ascii file
Posted by:"gpat" (gp..@mail.otenet.gr)
Date:Mon, 3 Oct 2005 12:05:59 +0100

Dear Sirs ,

I am using the following procedure to print ascii files in Delphi 4 , but in
the line
WritePrinter(hPrinter, Buffer, Count, BytesWritten)
i get a not suitable parameters error.
Anyone can help ?
The procedure is working fine in Delphi 2 .


procedure PrintFile1(const sFileName: string);
const
  BufSize = 16384;
type
  TDoc_Info_1 = record
    pDocName: pChar;
    pOutputFile: pChar;
    pDataType: pChar;
  end;
var
  Count: DWORD;
  BytesWritten:LPDWord;
  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
{  Printer.PrinterIndex := PrIndex;}
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  if not WinSpool.OpenPrinter(@Device, hPrinter, nil) then exit;
  DocInfo.pDocName := 'MyDo';
  DocInfo.pOutputFile := nil;
  DocInfo.pDatatype := 'RAW';
  if StartDocPrinter(hPrinter, 1, @DocInfo) = 0 then
  begin
    WinSpool.ClosePrinter(hPrinter);
    exit;
  end;
  if not StartPagePrinter(hPrinter) then
  begin
    EndDocPrinter(hPrinter);
    WinSpool.ClosePrinter(hPrinter);
    exit;
  end;
  AssignFile(f, sFileName);
  Reset(f,1);
  GetMem(Buffer, BufSize);
  while not eof(f) do
  begin
    Blockread(f, Buffer^, BufSize, Count);
    if Count > 0 then
    begin
     { here the compiler finds wring parameters **************}
      if not WritePrinter(hPrinter, Buffer, Count, BytesWritten) then
      begin
        EndPagePrinter(hPrinter);
        EndDocPrinter(hPrinter);
        WinSpool.ClosePrinter(hPrinter);
        FreeMem(Buffer, BufSize);
        exit;
      end;
    end;
  end;
  FreeMem(Buffer, BufSize);
  EndDocPrinter(hPrinter);
  WinSpool.ClosePrinter(hPrinter);
end;

Info

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive