VB5 Default Printer Switch Issue - SetdefaultprinterinVB5issue.txt [01/01] 
Author Message
 VB5 Default Printer Switch Issue - SetdefaultprinterinVB5issue.txt [01/01]

VB5 has a problem in using the technique documented in VB4 and VB5 to switch
the default printer. Under both compilers the documented method (shown in the
Printers/Printer Object/Collection Help article) is to traverse the printer
collection seeking a printer object with a property unique to the particular
printer you wish to set to default (DevName or DrvName) and then set a printer
object to that device. This worked in VB4 with no problem but did not work in


I think I've found a potential solution to the 'set default printer'
problem in VB 5 that we had discussed. I just had the chance to code it
on Monday. We're getting an engineer to add it to the KB, but I wanted
to let my customers (3 of them right now with this issue!) know what I'd
found as soon as possible. This program works on Win95 only. WinNT
doesn't support the use of PRINTER_INFO_5. The code would need to be
translated to use the Attribute member of PRINTER_INFO_2 instead.

> I've attached my sample VB5 project as a ZIP file. The ZIP file
> contains the VBP, VBW and FRM file. The project doesn't require any
> special location.

> The SETPRINT.FRM form contains a list and a commandbutton. The list is
> populated with the available printers, from the Printers collection
> DeviceName property.  Select a printer from the list, and press the
> commandbutton. This should set the default printer to the one
> selected, and print a short message of the form: "This output should
> go to <printer name> on port <portname>".

> All the action occurs in the command click. What it does is:

> 1) Determines which printer you've selected from the list

> 2) Uses OpenPrinter() to get a handle to this printer name

> 3) Uses this handle to call GetPrinter(), first, in order to find out
> how large an array we need for the return values, then, to obtain the
> return values

> 4) Populates a PRINTER_INFO_5 structure with the return information
> from GetPrinter(). There's a minor mess translating the long pointers
> from the return array into actual VB strings. he critical member is
> PRINTER_INFO_5's Attribute member, which we set to the constant:

> 5) Calls SetPrinter with the handle from step 2 and the PRINTER_INFO_5
> structure from step 4

> 6) Prints the sample string

> 7) Closes the printer handle

> There's some complexity in the General Declarations for dumb reasons.
> OpenPrinter in step 2 needs a PRINTER_DEFAULTS structure, in which is
> imbedded a DEVMODE structure. This is the reason for the 2 long TYPEs
> in General Declarations. For these purposes, we don't even care what's
> in them, we just need the space set aside correctly.

> I hope you find this information helpful.

> Brian W. Nash
> Microsoft Developer Support

begin 600 Setprint.zip


I've been talking to MS about it for a week or so.  Brian Nash with Microsoft
has recently come up with a hack to get around this problem.  This only works
on Win95 systems at the moment (he's getting some kind of stupid message from
WinNT when he tries the same thing). As a result it will be awhile before the
work around is posted officially on the MS KB. Brian has kindly given me his
permission to post the hack on this news group as long as it is understood
that this work around is unofficial until they get it completely working on
WinNT as well as Win95 and can post it to the KB.

The attached file is an e-mail I got from Brian with an embedded UUE Zip file
containing a VB5 project that details the work around and tests it.  The only
problem I experienced with it was that when I loaded it into VB5 it complained
that it couldn't load MSRDC20.OCX. I told it to ignore it and it worked just
fine without the control.

Note that unlike the method detailed above that worked in VB4, the system
default printer is set, not just the VB default printer. Therefore you might
want to make sure you save the name of the default printer going and and then
restore it to the default going out.

Mon, 27 Sep 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp - vb.txt [01/01]


3. Conversion vb3 > vb5 - news.txt [01/01]

4. Convert gifs to bload format - gif2bsv.exe [01/01]

5. VB OLE to MS Word - code.txt [01/01]

6. Importing a text file - Smallctx.txt [01/01]

7. Putting Text into Grid - dbase.nx [01/01]

8. VB OLE MS Word - code.txt [01/01]

9. Coolbar Code example - coolbar.zip [01/01]

10. Tabs in VB 3.0? - tabbed.zip [01/01]

11. Read this pleeeeease (DLL problems) - vb.txt [01/01]

12. Problem(s) with vba2.dll - vb.txt [01/01]


Powered by phpBB® Forum Software