🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Windows Printers

#12521
From: John Scott
Date: Mon, 01 Dec 2003 16:16
103 lines
4543 bytes
Thanks again. I tried your corrections - it runs without error but the
WritePrinter() function does not seem to work. When I check in the debugger
the function returns 0 which indicates an error I believe.
I am testing by sending the PCL code to rotate text 90deg. Nothing is
printed.
The code I am using is:

  char *PCLSideTwo;
   PCLSideTwo="\x01B&a90P John Scott"; //"\x01b&a2G"; // string to make PCL
printer change to side two Ec&a2G
  //  \x01B&a90P   should rotate text by 90 degrees to test since my printer
will not duplex
...
    // First set printer to correct printer
    TLocateOptions Opt;
    DM->tblPrinters->Locate("PRINTERID", StrToInt(NoteType)+1, Opt);
    for (int i=0; i< Printer()->Printers->Count; i++)
    {
      if (Printer()->Printers->Strings[i]==DM->tblPrintersNAME->Value)
      {
         Printer()->PrinterIndex=i;
         break;
      }
    }
    // Nov 2003 to print double sided
    char ADevice[256]={0}, ADriver[256]={0}, APort[256]={0};
    THandle  ADeviceMode;
    Printer()->GetPrinter(ADevice, ADriver, APort, ADeviceMode);
    Printer()->SetPrinter(ADevice, ADriver, APort, ADeviceMode);
    // end of add Nov 2003
 ...
              //RECT Rect;
             // Rect.top=0;
             // Rect.left=0;
             // Rect.right=2*DpiX;
             // Rect.bottom=Rect.top+2*DpiY;
             // DrawText(Printer()->Handle, PCLSideTwo,-1,&Rect,
DT_NOCLIP+DT_NOPREFIX);
              unsigned long x;
              int
y=WritePrinter(Printer()->Handle,PCLSideTwo,sizeof(PCLSideTwo), &x);
When executed: ADevice contains the printer name, y is 0, x is 116 and
nothing is printed.
If I try the commented code using DrawText() then the \x01B prints as a
small square and the remaning text of PCLSideTwo is printed.
I appreciate your help - do you have any more suggestions about how I can
get a PCL code to print?

John

> A couple things. The pointer parameters must point to an
> allocated buffer. You can dyamically allocate one chunk from
> the heap and assign the pointers:
>
>     char* ADevice = new char[ 256 * 3 ];
>     char* ADriver = (char*)ADevice + 256;
>     char* APort   = (char*)ADriver + 256;
>
> The casting most likely isn't needed but I can't help myself.
> Don't forget to delete [] ADevice;
>
> OR ... you can allocate it from the stack:
>
>     char ADevice[ 256 ] = { 0 };
>     char ADriver[ 256 ] = { 0 };
>     char APort[ 256 ]   = { 0 };
>
> >    int  ADeviceMode;
>
> Although an int is most likely ok here, it should be a THandle:
>
>     THandle ADeviceMode;
>
> >    DEVMODE DMode;
>
> Get rid of this line.
>
> >    Printer()->GetPrinter(ADevice, ADriver, APort, DMode);
>
> Replace the DMode parameter with ADeviceMode:
>
>     Printer()->GetPrinter(ADevice, ADriver, APort, ADeviceMode);
>
> >    Printer()->SetPrinter(ADevice, ADriver, APort, DMode);
>
> Same here:
>
>     Printer()->SetPrinter(ADevice, ADriver, APort, ADeviceMode);
>
> You also didn't show that you were setting the Printer()->PrinterIndex.
> The final block of code should look something like this:
>
>     char ADevice[ 256 ] = { 0 };
>     char ADriver[ 256 ] = { 0 };
>     char APort[ 256 ]   = { 0 };
>     THandle ADeviceMode;
>
>     Printer()->PrinterIndex = a valid printer number
>     Printer()->GetPrinter( ADevice, ADriver, APort, ADeviceMode );
>     Printer()->SetPrinter( ADevice, ADriver, APort, ADeviceMode );
>
> ~ JD
>
Technical Details
Message-ID: <3fcb6984@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp.abs.net!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3fbcf9c2@newsgroups.borland.com> <3fbd8132$1@newsgroups.borland.com> <3fc77301@newsgroups.borland.com> <3fc7e524$1@newsgroups.borland.com> <3fca2474@newsgroups.borland.com> <3fcb2567$1@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-12-01 08:18:14 PST
From: "John Scott" <jscott@kw.igs.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3fbcf9c2@newsgroups.borland.com> <3fbd8132$1@newsgroups.borland.com> <3fc77301@newsgroups.borland.com> <3fc7e524$1@newsgroups.borland.com> <3fca2474@newsgroups.borland.com> <3fcb2567$1@newsgroups.borland.com>
Subject: Re: Windows Printers
Date: Mon, 1 Dec 2003 11:16:02 -0500
Lines: 105
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 216.16.227.113
Message-ID: <3fcb6984@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1070295428 216.16.227.113 (1 Dec 2003 08:17:08 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp.abs.net!ash.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail