🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Does printer Escape PASSTHROUGH actually work?

#3150
From: Bob Gonder
Date: Tue, 22 Aug 2006 13:30
67 lines
2789 bytes
Keith wrote:

>typedef struct
>{
>     WORD wSize;
>     BYTE bData[2];                  // placeholder
>} PASSTHROUGHSTRUCT, FAR *LPPTS;
>
>LPPTS m_lpPTS;

Don't rely on "magic".
You rely on m_lpPTS being NULL, so set it.
	LPPTS  m_lpPTS = NULL;

>if (!m_lpPTS)
>  {
>  m_lpPTS = (LPPTS)GlobalLock(GlobalAlloc(GPTR, sizeof(WORD) +
>                                     2048));

Incorrect.
GPTR includes GMEM_FIXED, which is already locked, AND it returns the
Address, not a Handle. Also not sure why you want is Zero Initialized.

	m_lpPTS = (LPPTS)GlobalAlloc(GMEM_FIXED, 2050 );

>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);
>  }

You don't check for failure of the Escape.
You only check if it is implimented (zero return).
Are you sure the printer wants to see the size field?
I would think this would be more appropriate...

static  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";

  rv=Escape( m_dcPrint ,PASSTHROUGH, sizeof(PrintThis)-1, PrintThis);
  if( rv <= 0 )
  {
	/* handle error */
	break;
   };

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

You forgot GlobalFree()
Also, since your Lock was incorrect, the Unlock is too...

	EndPage(m_dcPrint);
	EndDoc(m_dcPrint);
	GlobalFree(m_lpPTS);
	m_lpPTS = NULL;

I also didn't see where you actually Opened the Printer, or Closed it.
Technical Details
Message-ID: <osvle2ptsnkmjhu9shd2hmgq9h6kb69r53@4ax.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <44EA7A75.C70EC63A@sbcglobal.net>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cd89a6d0cbcf8d4a
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Does printer Escape PASSTHROUGH actually work?
Date: Tue, 22 Aug 2006 06:30:28 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <osvle2ptsnkmjhu9shd2hmgq9h6kb69r53@4ax.com>
References: <44EA7A75.C70EC63A@sbcglobal.net>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.84.122
X-Trace: newsgroups.borland.com 1156253425 69.69.84.122 (22 Aug 2006 06:30:25 -0700)
Lines: 69
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail