home *** CD-ROM | disk | FTP | other *** search
Wrap
PPRTR.DLL copyright 1992, 1993 Paul F. Poellinger, Silent O Software ------------------------------------------------------------------- REVISION HISTORY ------------------------------------------------------------------- v4.1 -- restores "not found" error code 998 for when bad printer name is passed to DefPrtr...left out in 4.0 conversion v4.0 -- strings passed from Prtrs, GetPrtr, DefPrtr now contain " on xxxx.." where xxxx.. is the port. Required to accomodate a printer of the same type on more than one port. Previously, I ignored all but the first. -- added explanatory note about how Visual Basic handles device contexts and DEVMODES, and the allowed points for changing stuff NOTE: Code written to work with prior versions of these functions should be checked for compatibility with this version's. The calling sequences are the same, but as noted above, the strings now include port info. ------------------------------------------------------------------- v3.1 -- contains a fix for user defined page length/width NOTE: When setting a user-defined pagelength or pagewidth, you do not need to change the pagesize to user-defined first...the pagelength/pagewidth actions do it for you. -- added GetPort function ------------------------------------------------------------------- v3.0 -- added PrtrCap, GetPrtr functions ------------------------------------------------------------------- v2.0 -- fixed copies error ------------------------------------------------------------------- Included: PPRTR DLL The real deal. READ ME self-reference (this). PPRTR FRM .. \ Visual Basic PPRTR MAK ..> (version 3.0) PPRTR BAS .. / example of PPrtr functions. PPRTR EXE .. \ Example VB3.0 program EXE and PPRTRFRM TXT ..> saved text for users without PPRTRBAS TXT .. / v3.0 of VB (EXE needs VBRUN300.DLL PPGLOBAL TXT VB constants. PRINT TXT constant definitions from C header file. DEVCAP TXT device cap definitions from C hdr file. PPRTR LIB Import library for C. PPRTR H Header file for C. functions: PPrtr -- allows retrieval or change to any attribute of the default printer DefPrtr -- allows you to find out or change the default printer Prtrs -- returns semi-colon delimeted list of available active printers PrtrCap -- returns structure (VB type) containing default printer device capabilities GetPrtr -- returns the name of the current default printer GetPort -- returns the port of the current default printer ----------------------------------------------------------------------- function prototypes: ( in C format ) : int FAR PASCAL PPrtr (HWND hwndx, int selection, int NewValue, int action); int FAR PASCAL Prtrs (LPSTR szActives); int FAR PASCAL DefPrtr (LPSTR szNewPrinter, LPSTR szOldPrinter); int FAR PASCAL GetPrtr (LPSTR szPrtr); int FAR PASCAL GetPort (LPINT szPort); int FAR PASCAL PrtrCap (LPINT nDevCap); ----------------------------------------------------------------------- function definitions: ( in Visual Basic format ) : ******************************** PPrtr ********************************** Declare Function PPrtr Lib "PPRTR.DLL" (ByVal hWnd As Integer, ByVal ppSelection As Integer, ByVal PPNewValue As Integer, ByVal ppAction As Integer) As Integer where: hWnd ................ is a window handle ppSelection ......... is the selected printer device attribute to get/change. ... NOTE that not all printers support all actions (e.g. my Epson LX-800 doesn't support PaperLength or PaperWidth) ppNewValue .......... is the value to change it to ... (anything will do call is a gimme, no change ) ... see PPGLOBAL.TXT for available values ppAction ............ is the action requested ... 0 = gimme current value ... 1 = change it to ppNewValue returns ......... integer of value of selected attribute before the call ... 996 when the ppSelection is not supported by the default printer driver ... 997 for a bad ppSelection code parameter ... 998 for a bad ppAction code parameter ... 999 when it can't find printer/driver info ppSelection: DM_ORIENTATION = &H1 DM_PAPERSIZE = &H2 DM_PAPERLENGTH = &H4 DM_PAPERWIDTH = &H8 DM_SCALE = &H10 DM_COPIES = &H100 DM_DEFAULTSOURCE = &H200 DM_PRINTQUALITY = &H400 DM_COLOR = &H800 DM_DUPLEX = &H1000 DM_YRESOLUTION = &H2000 DM_TTOPTION = &H4000 Samples: PPrtr(hWnd, DM_PAPERSIZE, PP_UNNEEDED, PP_GIMME)) PPrtr(hWnd, DM_ORIENTATION, PP_UNNEEDED, PP_GIMME)) PPrtr(hWnd, DM_ORIENTATION, DMORIENT_PORTRAIT, PP_CHANGE_IT)) PPrtr(hWnd, DM_PAPERSIZE, DMPAPER_LEGAL, PP_CHANGE_IT)) C programmers...the relavent header file for this call is PRINT.H (in Borland C++) ******************************** DefPrtr *******************************- Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer where: newone .. is a string corresponding to what you see in the control panel printers dialog box. It shows printer names followed by "on xxxx:" where xxxx is a port. Don't use one where it says "on None". HP LaserJet Series II on LPT1: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^-- all this This is case insensitive, but otherwise must be identical. Note: the printer must have been made "active" in the control panel printers applet...it'll show "None" for a port if it's not...e.g. active -> HP LaserJet Series II=HPPCL,LPT1: not ----> HPGL Plotter=MGXHPGL,None Note: the printer may be active on more than one port. It'll show the additional ports on the same line separated by commas...e.g. 1 port -> HP LaserJet Series II on LPT1: 3 ports -> HP LaserJet Series II on LPT1:, LPT2:, COM2: To use the LPT2 printer, pass this: HP LaserJet Series II on LPT2: Passing this parameter as an empty string or unrecognizable string results in a 998 error, but does return the name of the current printer in the "oldone" parameter...thus, allowing retrieval of the name of the current default printer without changing anything: currentptr$ = String$(255, 0) i = DefPrtr("", currentptr$) where: oldone .. is a string in which the function will return the default printer before your call. Save this for use as "newone" to reset the printer to the prior default printer when and if you desire to do so. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. oldptr$ = String$(255, 0) i = DefPrtr("HP LaserJet Series II on LPT1:", oldptr$) returns: 0 = successful 999 = Unable to write to WIN.INI ... this is a system problem. 998 = The "newone" printer was not found in [devices] section of WIN.INI ... be sure you've put in all spaces 997 = The "newone" printer was found, but it is not "active"...i.e. its port is "None" Sample: Declare Function DefPrtr Lib "PPRTR.DLL" (ByVal newone As String, ByVal oldone As String) As Integer //---- change to LaserJet --------------------- oldprinter$ = String$(255, 0) i = DefPrtr("HP LaserJet Series II on LPT1:", oldprinter$) //---- . . print to LaserJet . //---- change back to original printer -------- dontcare$ = String$(255, 0) i = DefPrtr(oldprinter$,dontcare$) ******************************** Prtrs *******************************- Declare Function Prtrs Lib "PPRTR.DLL" (ByVal pList As String,) As Integer where: pList ... is a string for the return of a list of available active printers. The list only contains the names of "active" printers. The printer must have been made "active" in the control panel printers applet...it'll show "None" for a port if it's not...e.g. active -> HP LaserJet Series II=HPPCL,LPT1: not ----> HPGL Plotter=MGXHPGL,None Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. plist$ = String$(255, 0) i = Prtrs(plist$) The active printer names are separated by semi-colons (;), e.g. Epson LX-800 on LPT1:;HP LaserJet Series II on LPT2: returns ....... 0 if no active printers found, or unable to access [drivers] section in WIN.INI ....... 999 if the substring " on " cannot be found in the string you passed, or ....... the length of the returned string ******************************** PrtrCap *******************************- Declare Function PrtrCap Lib "PPRTR.DLL" (ndc As DEVCAP) As Integer where: ndc .. is a structure (VB type definition) containing the device capability variable definitions: Type devcap DRIVERVERSION As Integer TECHNOLOGY As Integer ' bits HORZSIZE As Integer VERTSIZE As Integer HORZRES As Integer VERTRES As Integer BITSPIXEL As Integer PLANES As Integer NUMBRUSHES As Integer NUMPENS As Integer NUMMARKERS As Integer NUMFONTS As Integer NUMCOLORS As Integer PDEVICESIZE As Integer CURVECAPS As Integer ' bits LINECAPS As Integer ' bits POLYGONALCAPS As Integer ' bits TEXTCAPS As Integer ' bits CLIPCAPS As Integer ' bits RASTERCAPS As Integer ' bits ASPECTX As Integer ASPECTY As Integer ASPECTXY As Integer LOGPIXELSX As Integer LOGPIXELSY As Integer SIZEPALETTE As Integer NUMRESERVED As Integer COLORRES As Integer End Type See the PPGlobal.txt file for 'bit' field masks; and see the VB example for sample usage. See the windows SDK documentation for explanation of the dev cap fields. Returns 0 always. ******************************** GetPrtr *******************************- Declare Function GetPrtr Lib "PPRTR.DLL" (ByVal DefP As String) As Integer where: DefP .. is a string set up to receive the name of the current default printer. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. defptr$ = String$(255, 0) i = GetPrtr(defptr$) Returns 0 -- and printer name in the string if successful; if not, string is as you initialized it. ******************************** GetPort *******************************- Declare Function GetPort Lib "PPRTR.DLL" (ByVal DefP As String) As Integer where: DefP .. is a string set up to receive the name of the current default printer port. Note: in Visual Basic you must pre-load a string which is to be filled by a called function...e.g. defptr$ = String$(255, 0) i = GetPort(defptr$) Returns 0 -- and printer name in the string if successful; if not, string is as you initialized it. -------------------------------------------------------------------- Visual Basic programmers, PLEASE READ: Windows programs, including VB, print to a virtual printer called a Device Context, or DC. When you start a print job by performing any print action, VB gets a new DC...this attaches printer setting data from a structure called DEVMODE. From then till you issue an ENDDOC, setting changes like orientation or default printer are not recognized. It appears as tho the dll calls didn't work, when in fact they worked but were ignored. So, you must make pprtr.dll calls before your first print action, or after the ENDDOC if you want to change stuff between print jobs. -------------------------------------------------------------------- My next version will manage DCs so that setting changes can be made on the fly. That'll allow orientation changes in mid-job, for example. I'll also support multiple DCs, which will allow you to create print jobs to more than one printer simultaneously, or more than one job for the same printer at the same time (they print separately, not mixed). BTW, it also contains functions for printing the screen, window or client area; printing to or from a file; printing the clipboard or capturing the screen, window or client area to the clipboard or a file; loading a file to the clipboard. It'll print all this stuff to a fax, too, by temporarily changing the default printer to your fax...after you make a call identifying it. If you're registered, I'll e-mail you a notice when I finish testing it...the coding's done, but testing is tedious. Beta testers would be welcome. -------------------------------------------------------------------- This DLL has been extensively tested by me and friends, but YMMV. A tip of the pelican's beak to OsoSoft George Campbell who suggested the original idea for this DLL. You are free to try this DLL for 30 days. If you decide to use it thereafter, you are obligated to send $10 to PAUL POELLINGER 2019 Round Lake Drive Houston, TX 77077 Please include you e-mail address if you have one. -- OR -- register via Compuserve's shareware registration service by typing GO SWREG at the prompt. (Note: I only net $8.50 this way :-( After doing so, you are free to use it in your applications, and to distribute it with such applications, as long as you do not charge separately for the DLL or publish its calling conventions. Please note that even if you paid for a diskette or CD containing this package, you must still pay the $10 registration fee for use of this DLL past the 30 day free trial. If you paid for the earlier version, you've paid for this one. I and all those dependent on me thank you. You are free to pass this package on to others or upload it to bulletin boards provided that 1) you do not charge for it above the cost of distribution, and 2) all parts of the package are included (see "included" at the top). Thank you for supporting shareware. ------------------------------------------------------------------- Let me know if you have any trouble or suggestions. Paul Poellinger Code Wallah Silent O Software Purveyors of Peliware Compuserve 70732,3576 11-18-93