Ok, so with adding some of the LCL unit-directories from Lazarus to the search-unit-directories of FP.EXE, the printers-unit can be used. (You do need the complete source of Lazarus or extract the appropriate units).
Yeah, it would be easier if the base-code of the printers was moved to the FPC-project.
Anyway... printing to a Windows-printer could be done like this without using the printers-unit. This example is for Windows-only (I assume this is fine because we were talking about "Windows"-printers
):
program test;
{$mode objfpc}{$H+}
uses jwawinbase, Windows;
function GetDefaultPrinter: string;
var
DefaultPrinter: array [0 .. 79] of Char;
I: Integer;
begin
GetProfileString('windows', 'device', '', DefaultPrinter, SizeOf(DefaultPrinter) - 1);
I := Pos(',', DefaultPrinter);
if I = 0 then I := Length(DefaultPrinter) + 1;
GetDefaultPrinter := Copy(DefaultPrinter, 1, I - 1);
end;
procedure Printing(const sPrinter: string);
var
pDc: hDc;
DocInfo: TDocInfo;
S: String;
begin
pDc := CreateDC(pchar('WINSPOOL'), pchar(sPrinter), nil, nil);
try
FillChar(DocInfo, SizeOf(DocInfo), #0);
DocInfo.cbSize := SizeOf(DocInfo);
DocInfo.lpszDocName := 'Myprogram';
if StartDoc(pDc, DocInfo) = 0 then
Exit;
if not StartPage(pDc) = 0 then
begin
EndDoc(pDc);
Exit;
end;
S := 'Hello World';
TextOut(pDc, 200, 200, @S[1], Length(S));
EndPage(pDc);
EndDoc(pDc);
finally
DeleteDc(pDc);
end;
end;
begin
Printing(GetDefaultPrinter);
end.
Margins, pagelength and fonts could all be accounted for and you could create a simple writeln-procedure which does NewPage etc.