enumerate windows printers

!--------------------------------------------------------------------------------------------
! Ralf Schoeffler http://www.schoeffler.biz mailto:info@schoeffler.biz
!-----------------------------snipp ---------------------------------------------------------
! inside the global map

MODULE('WINAPI')

EnumPrintersA(ULONG,*CSTRING,ULONG,*BYTE,ULONG,*ULONG,*ULONG),BOOL,PASCAL,RAW
END

!--------------------------------------------------------------------------------------------
!DATA
flag         ULONG
pname        CSTRING(255)
level        ULONG
cbBuf        ULONG
cbBuffer     STRING(65536)
pcbNeed      ULONG
pcRetrun     ULONG
pPrinterEnum BYTE OVER(cbBuffer)
ret          LONG
zeiger       LONG,DIM(16384) OVER(cbBuffer)
tstr         STRING(250)
tbyte        BYTE
pPrinter     Queue
Name           STRING(32)
Port           STRING(60)
SPrinter       BYTE
END


!--------------------------------------------------------------------------------------------
!CODE
flag      = 2                    ! PRINTER_ENUM_LOCAL
pname     = ''                   ! Cstring(255)
level     = 2                    ! Printer_Info_2
cbBuf     = 65536                ! Size of cbpBuffer
pcbNeed   = 0                    ! Structur as bytes
pcRetrun  = 0                    ! count of printers
ret       =
EnumPrintersA(flag,pname,level,pPrinterEnum,cbBuf,pcbNeed,pcRetrun)
loop p# = 0 to pcRetrun - 1
   clear(pPrinter)
   !-------------------------------------------------------------------------------------------
   ! printername
   !-------------------------------------------------------------------------------------------
   tstr = ''
   loop i# = 0 to 32
     peek(zeiger[2+(p#*21)]+i#, tbyte)
     if tbyte = 0 then break end
     tstr[i#+1] = chr(tbyte)
   end
   pPrinter:Name = tstr
   !-------------------------------------------------------------------------------------------
   ! Standard Printer
   !-------------------------------------------------------------------------------------------
   if clip(pPrinter:Name) = clip(PRINTER{PROPPRINT:Device}) then
     pPrinter:SPrinter = 1
   end
   !-------------------------------------------------------------------------------------------
   ! Printerport
   !-------------------------------------------------------------------------------------------
   tstr = ''
   loop i#=0 to 32
     peek(zeiger[4+(p#*21)]+i#,tbyte)
     if tbyte=0 then break end
     tstr[i#+1]=chr(tbyte)
   end
   pPrinter:Port = tstr
   pPrinters = pPrinter
   add(pPrinters)
end !loop
!-----------------------------snipp ---------------------------------------------------------

Schreibe einen Kommentar