🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Windows Printers

#12520
From: JD
Date: Mon, 01 Dec 2003 10:26
56 lines
2531 bytes
"John Scott" <jscott@kw.igs.net> wrote:
> [...] Could you point out the error?

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: <3fcb2567$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!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>

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 03:39:17 PST
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: Re: Windows Printers
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 172.148.36.185     
References: <3fbcf9c2@newsgroups.borland.com> <3fbd8132$1@newsgroups.borland.com> <3fc77301@newsgroups.borland.com> <3fc7e524$1@newsgroups.borland.com> <3fca2474@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <3fcb2567$1@newsgroups.borland.com>
Date: 1 Dec 2003 03:26:31 -0700
X-Trace: newsgroups.borland.com 1070277991 207.105.83.66 (1 Dec 2003 03:26:31 -0700)
Lines: 57
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail