• Welcome to Jose's Read Only Forum 2023.
 

GDI: EnumPorts Function

Started by José Roca, August 22, 2011, 01:54:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The following example enumerates the ports that are available for printing on the local server.


' ########################################################################################
' The following example enumerates the ports that are available for printing on the local server.
' ########################################################################################

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

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

   LOCAL cbNeeded AS LONG
   LOCAL cReturned AS LONG
   LOCAL i AS LONG
   DIM   Ports(0) AS PORT_INFO_1

   EnumPorts(BYVAL %NULL, 1, BYVAL %NULL, 0, cbNeeded, cReturned)
   IF cbNeeded THEN
      REDIM Ports(0 TO cbNeeded \ SIZEOF(PORT_INFO_1))
      EnumPorts BYVAL %NULL, 1, Ports(0), _
                SIZEOF(Ports(0)) * (UBOUND(Ports) + 1), cbNeeded, cReturned
      PRINT " #", "Port name"
      PRINT " -", "---------"
      FOR i = 0 TO cReturned - 1
          PRINT i, Ports(i).@pName
      NEXT
   END IF

   WAITKEY$

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