🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12693

Re: Windows Printers

#12693
From: Peter Rees
Date: Fri, 21 Nov 2003 03:06
64 lines
2779 bytes
Albert

> In Windows 95, 98 & Me, I can send raw text directly to a Generic/Text
Only
> Windows printer using TPrinter but this doesn't work in XP & 2000.  Does
> anyone know of a solution to this?
>
> If I can't use TPrinter to print, does anyone know how to find out the
port
> name from a Windows printer?  I tried TPrinter::GetPrinter() but I got
junk
> except for ADevice.  I also tried GetPrinter() but I just got blank
strings
> for the strings in PRINTER_INFO_2.

You can print to a printer on any version of windows in RAW mode as below
(not tested). Note however that not all printers support RAW mode,
particularly the really cheap inkjets.

Peter


#define BIG_BUFFER (1024*32)

  int PrintFileRaw(char *cPrinterName, char *cFileName)
{
 int rVal = -1;
 char bigBuffer[BUG_BUFFER];
 HANDLE  hPrinter, hFile ;
  DOC_INFO_1 DocInfo ;
  DWORD nRead, nWritten, rVal = -1 ;
    if ( OpenPrinter(cPrinterName, &hPrinter, NULL) != 0 ) {
        DocInfo.pDocName = cFileName ;
      DocInfo.pOutputFile = NULL ;
      DocInfo.pDatatype = "RAW" ;
      if ( StartDocPrinter(hPrinter,1,(char *) &DocInfo) != 0 ) {
        if ( StartPagePrinter(hPrinter) != 0 ) {
          hFile =
CreateFile(cFileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL
,NULL)   ;
          if (hFile != INVALID_HANDLE_VALUE ) {
            while (ReadFile(hFile, printBuffer, BIG_BUFFER, &nRead, NULL) &&
(nRead > 0))
              WritePrinter(hPrinter, printBuffer, nRead, &nWritten) ;
            rVal = 1 ;
            CloseHandle(hFile) ;
          }
          else
            rVal= -6 ;
          EndPagePrinter(hPrinter) ;  // 28/11/2001 10:16
        }
        else
          rVal = -4 ;
        EndDocPrinter(hPrinter);
      }
      else
        rVal= -3 ;
      ClosePrinter(hPrinter) ;
    }
    else
       rVal= -2 ;
  }
  return(rVal) ;
}
Technical Details
Message-ID: <3fbd8132$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3fbcf9c2@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,7b2449597708bec
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-20 19:09:31 PST
From: "Peter Rees" <peter@NOOSPAMMrees.co.nz>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3fbcf9c2@newsgroups.borland.com>
Subject: Re: Windows Printers
Date: Fri, 21 Nov 2003 16:06:52 +1300
Lines: 66
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 219.88.101.36
Message-ID: <3fbd8132$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069383986 219.88.101.36 (20 Nov 2003 19:06:26 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail