SplEnumPort - Example Code

This sample code will print out all the ports an associated information. This is done at level 1, and for the local workstation.

#define INCL_DOSMEMMGR
#define INCL_SPL
#define INCL_SPLDOSPRINT
#define INCL_SPLERRORS

#include <os2.h>
#include <stdio.h>

INT main ()
{
   SPLERR splerr ;
   ULONG  cbBuf ;
   ULONG  cTotal;
   ULONG  cReturned ;
   ULONG  cbNeeded ;
   ULONG  ulLevel = 1;
   ULONG  i ;
   PSZ    pszComputerName = NULL;
   PVOID  pbuf ;
   PPRPORTINFO1 pPort1 ;

   splerr = SplEnumPort(pszComputerName, ulLevel, pbuf, 0L, /* cbBuf */
                            &cReturned, &cTotal,
                            &cbNeeded, NULL) ;

   if (splerr == ERROR_MORE_DATA || NERR_BufTooSmall )
   {
      if (!DosAllocMem( &pbuf, cbNeeded,
                        PAG_READ|PAG_WRITE|PAG_COMMIT) )
      {
          cbBuf = cbNeeded ;
          splerr = SplEnumPort(pszComputerName, ulLevel, pbuf, cbBuf,
                                  &cReturned, &cTotal,
                                  &cbNeeded, NULL) ;
          if (splerr == 0L)
          {
             pPort1 = (PPRPORTINFO1)pbuf ;
             printf("Port names: ");
             for (i=0; i < cReturned; i++)
             {
                printf("Port - %s, Driver - %s Path - %s\n              ",
                       pPort1->pszPortName, pPort1->pszPortDriverName,
                       pPort1->pszPortDriverPathName ) ;
                pPort1++ ;
             }
             printf("\n");
          }
          DosFreeMem(pbuf) ;
      }
   }
   else
   {
      printf("SplEnumPort splerr=%ld, \n",splerr) ;
   }
   DosExit( EXIT_PROCESS , 0 ) ;
   return (splerr);
}   /* end main */


[Back: SplEnumPort - Related Functions]
[Next: SplEnumPort - Topics]