Author Topic: GDI: EnumPorts Function  (Read 4153 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2530
  • User-Rate: +209/-0
  • Gender: Male
GDI: EnumPorts Function
« on: August 22, 2011, 01:54:31 PM »
 
The following example enumerates the ports that are available for printing on the local server.

Code: [Select]
' ########################################################################################
' 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
' ========================================================================================