Subject Re: printer paper source
From Mervyn Bick <invalid@invalid.invalid>
Date Tue, 11 Aug 2020 16:58:09 +0200
Newsgroups dbase.getting-started
Attachment(s) list_sPaperName.prg

On 2020-08-10 19:35, Ken Mayer wrote:

> Okay, well ... when I run papersize this is the output:
>
> HP LaserJet 1020
>           1 - Letter
>           5 - Legal
>           7 - Executive
>           9 - A4
....
>         260 - Post Card
>         258 - 8.5x13
>         257 - 16K
>         256 -
>
> Note that 256 doesn't have anything after it.

Just out of curiosity would you run the attached program.  It should
print the last three paper sizes character by character with each
character on a new line.  The initial character of each name will be
against the left margin and the remaining 63 characters will be indented.

This should show if the last paper size is empty or not.  If it starts
with a 0 then this is an error as that is used as an end-of-string
marker.  If there are characters following the initial 0 then
PaperSize.prg can probably be modified to ship leading zeros.

Mervyn.



clear
#define  DC_PAPERNAMES     16
#define  DC_PAPERS         2
#define  ZEROS(n)          replicate(chr(0), n)
parameters cDevice

initExterns()
if not type("argVector(1)") == "C"
    cDevice  := getPrinterDefault()
endif
?cDevice
local a, i
a  =  getPapers( cDevice, "")
return



function getPapers(cDevice, cPort)
    local    aRet, cName, i, ii, lpDevMode, nPair, nWord,;
             sPaperName, sPaperSize
    lpDevMode   =  0
    // get the number of paperSize/paperName pairs.
    nPair =  RMM_DeviceCapability(;
             cDevice,;
             cPort,;
             DC_PAPERS,;
             null,;
             lpDevMode)
    if nPair > 0
       sPaperName  =  ZEROS(nPair * 64)
       // fill the paperName buffer.
       RMM_DeviceCapability(;
                cDevice,;
                cPort,;
                DC_PAPERNAMES,;
                sPaperName,;
                lpDevMode)
  
        for n = (nPair-3)*64 to len(sPaperName)
          ? iif(n%64 = 0,'','  ')
          ??iif(sPaperName.getByte(n) <> 0, chr(sPaperName.getByte(n)),'0')
        next
    endif
return

//------------------------------------------------------------//
// return the windows default printer as a string.
function getPrinterDefault
    Local sBuff, cRet, nLen
    sBuff =  ZEROS(250)
    nLen  =  RMM_GetWinIniString( ;
             "windows", "device", ;
             ",,,", sBuff, sBuff.length)
    cRet  =  sBuff.left(sBuff.indexOf(","))
return   cRet.rightTrim()

//------------------------------------------------------------//
// return a WORD from the string sValu starting at nByte.
function getWord(sValu, nByte)
return   int(sValu.getByte(nByte) + ;
          bitlshift(sValu.getByte(nByte + 1), 8))

//------------------------------------------------------------//
function initExterns
    if not type("RMM_DeviceCapability") == "FP"
       extern CINT RMM_DeviceCapability( ;
                CSTRING, CSTRING, CWORD, CPTR, CPTR);
                winspool.drv from 'DeviceCapabilitiesA'
    endif
    if not type("RMM_GetWinIniString") == "FP"
       extern CULONG RMM_GetWinIniString( ;
                CSTRING, CSTRING, CSTRING, CSTRING, CULONG);
                kernel32 from "GetProfileStringA"
    endif
return