Følgende er fra JCL:
procedure DirectPrint(const Printer7, Data: string);
type
TDoc_Info_1 = record
DocName: PChar;
OutputFile: PChar;
Datatype: PChar;
end;
var
PrinterHandle: THandle;
DocInfo: TDoc_Info_1;
BytesWritten: Cardinal;
Count: Cardinal;
Defaults: TPrinterDefaults;
begin
// Defaults added for network printers. Supposedly the last member is ignored
// by Windows 9x but is necessary for Windows NT. Code was copied from a msg
// by Alberto Toledo to the C++ Builder techlist and fwd by Theo Bebekis.
Defaults.pDatatype := PChar(\'RAW\');
Defaults.pDevMode := nil;
Defaults.DesiredAccess := PRINTER_ACCESS_USE;
Count := Length(Data);
if not OpenPrinter(PChar(Printer), PrinterHandle, nil) then
raise EJclPrinterError.CreateResRec(@RsInvalidPrinter);
// Fill in the structure with info about this \"document\"
DocInfo.DocName := \'My Document\';
DocInfo.OutputFile := nil;
DocInfo.Datatype := \'RAW\';
try
// Inform the spooler the document is beginning
if StartDocPrinter(PrinterHandle, 1, @DocInfo) = 0 then
EJclPrinterError.CreateResRec(@RsNAStartDocument);
try
// Start a page
if not StartPagePrinter(PrinterHandle) then
EJclPrinterError.CreateResRec(@RsNAStartPage);
try
// Send the data to the printer
if not WritePrinter(PrinterHandle, @Data, Count, BytesWritten) then
EJclPrinterError.CreateResRec(@RsNASendData);
finally
// End the page
if not EndPagePrinter(PrinterHandle) then
EJclPrinterError.CreateResRec(@RsNAEndPage);
end;
finally
// Inform the spooler that the document is ending
if not EndDocPrinter(PrinterHandle) then
EJclPrinterError.CreateResRec(@RsNAEndDocument);
end;
finally
// Tidy up the printer handle
ClosePrinter(PrinterHandle);
end;
// Check to see if correct number of bytes written
if BytesWritten <> Count then
EJclPrinterError.CreateResRec(@RsNATransmission);
end;