🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Does printer Escape PASSTHROUGH actually work?

#3146
From: Keith
Date: Tue, 22 Aug 2006 03:31
89 lines
3011 bytes
I have the following:

// in the header..........
typedef struct
{
     WORD wSize;
     BYTE bData[2];                  // placeholder
} PASSTHROUGHSTRUCT, FAR *LPPTS;

HANDLE m_dcPrint;
LPPTS m_lpPTS;

// in a button event handler
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TPrinter *Prntr=Printer();

char device[MAX_PATH], driver[MAX_PATH], port[MAX_PATH];
HANDLE HMem;

// get default printer device, driver, and port names
Prntr->GetPrinter(device, driver, port, (unsigned int)HMem);

m_dcPrint=Prntr->Handle;

int x=PASSTHROUGH;
if (Escape(m_dcPrint, QUERYESCSUPPORT, sizeof(x), (LPCSTR) &x, NULL)<=0)

  {
  ShowMessage("Printer does not support passthrough");
  return;
  }

if (HMem)
  {
  PDEVMODE pDevMode=(PDEVMODE)GlobalLock(HMem);
  pDevMode->dmCopies =1;
  GlobalUnlock(HMem);
  }

if (!m_lpPTS)
  {
  m_lpPTS = (LPPTS)GlobalLock(GlobalAlloc(GPTR, sizeof(WORD) +
                                     2048));
  if (m_lpPTS==0)
    {
    ShowMessage("Print Aborted, cannot lock memory");
    return;
    }
  }

DOCINFO mydoc;
mydoc.cbSize=sizeof(mydoc);
mydoc.lpszDocName="MyDoc";
memset(&mydoc,0,sizeof(mydoc));
StartDoc(m_dcPrint,&mydoc);
StartPage(m_dcPrint);

char *PrintThis="Now is the time for all good men to come to the aid of
his country and Liz need not be offended.\r\n"
m_lpPTS->wSize = strlen(PrintThis);

memcpy (m_lpPTS->bData, PrintThis, strlen(PrintThis));

int rv=1;
for (int i=0;rv && i<30;++i)
  {
  rv=Escape(m_dcPrint,PASSTHROUGH,sizeof(m_lpPTS->wSize) +
m_lpPTS->wSize,
         (LPSTR)m_lpPTS,0);
  }

EndPage(m_dcPrint);
EndDoc(m_dcPrint);
GlobalUnlock(m_lpPTS);
}

The above executes from top to bottom, no ShowMessage occurs, while
stepping the code in debug, the port and device are correct strings....
and the loop executes 30 iterations....however, not a single byte is
printed, nor is the spooler ever activated.

Any of you folks have an explanation why there is no printed output?
or, alternatively, any of you ever use the Escape to attempt to send
data, for instance, PCL-5 commands, to a HP laser printer?

TIA

keith
Technical Details
Message-ID: <44EA7A75.C70EC63A@sbcglobal.net>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cd89a6d0cbcf8d4a,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Message-ID: <44EA7A75.C70EC63A@sbcglobal.net>
Date: Mon, 21 Aug 2006 22:31:01 -0500
From: Keith <kdopson@sbcglobal.net>
X-Mailer: Mozilla 4.79 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Does printer Escape PASSTHROUGH actually work?
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 65.71.227.85
X-Trace: newsgroups.borland.com 1156217459 65.71.227.85 (21 Aug 2006 20:30:59 -0700)
Lines: 91
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail