• Welcome to Jose's Read Only Forum 2023.
 

GDI: EnumPrinters Function

Started by José Roca, August 22, 2011, 01:56:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The following example enumerates the printers using a Level 2.


' ########################################################################################
' The following example enumerates the printers using a Level 2.
' ########################################################################################

' SED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL Level AS LONG
   LOCAL cbNeeded AS LONG
   LOCAL cbReturned AS LONG
   LOCAL i AS LONG
   DIM   Pi2(0) AS LOCAL PRINTER_INFO_2

   Level = 2
   EnumPrinters %PRINTER_ENUM_CONNECTIONS OR %PRINTER_ENUM_LOCAL OR %PRINTER_ENUM_NETWORK, _
                BYVAL %NULL, Level, BYVAL %NULL, 0, cbNeeded, cbReturned
   REDIM PI2(0 TO cbNeeded \ SIZEOF(PI2(0)))
   EnumPrinters %PRINTER_ENUM_CONNECTIONS OR %PRINTER_ENUM_LOCAL OR %PRINTER_ENUM_NETWORK, _
         "", Level, BYVAL VARPTR(PI2(0)), SIZEOF(PI2(0)) * (UBOUND(PI2) + 1), _
         cbNeeded, cbReturned
   FOR i = 0 TO cbReturned - 1
      PRINT PI2(i).@pPrinterName "," PI2(i).@pDriverName "," PI2(i).@pPortName
   NEXT
   WAITKEY$

END FUNCTION
' ========================================================================================


José Roca

 
The following example enumerates the printers using a Level 5.


' ########################################################################################
' The following example enumerates the printers using a Level 5.
' ########################################################################################

' SED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG

   LOCAL Level AS LONG
   LOCAL cbNeeded AS LONG
   LOCAL cbReturned AS LONG
   LOCAL i AS LONG
   DIM   Pi5(0) AS LOCAL PRINTER_INFO_5

   Level = 5
   EnumPrinters %PRINTER_ENUM_LOCAL, BYVAL %NULL, Level, BYVAL %NULL, 0, cbNeeded, cbReturned
   REDIM Pi5(0 TO cbNeeded \ SIZEOF(Pi5(0)))
   EnumPrinters %PRINTER_ENUM_LOCAL, "", Level, BYVAL VARPTR(Pi5(0)), _
         SIZEOF(Pi5(0)) * (UBOUND(Pi5) + 1), cbNeeded, cbReturned
   FOR i = 0 TO cbReturned - 1
      PRINT Pi5(i).@pPrinterName "," Pi5(i).@pPortName
   NEXT
   WAITKEY$

END FUNCTION
' ========================================================================================