SplEnumDevice - Example Code

This sample code enumerates all the devices on the local workstation. It then prints out the information.

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

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

INT main ()
{
   ULONG  cbBuf ;
   ULONG  cTotal;
   ULONG  cReturned ;
   ULONG  cbNeeded ;
   ULONG  ulLevel = 3L;
   ULONG  i ;
   SPLERR splerr ;
   PSZ    pszComputerName ;
   PBYTE  pBuf ;
   PPRDINFO3 pprd3 ;

   pszComputerName = (PSZ)NULL ;

   /* Make the call with cBuf = 0 so that you will get the size of the */
   /* buffer  needed returned in cbNeeded.                             */
   splerr = SplEnumDevice(pszComputerName, ulLevel, pBuf, 0L, /* cbBuf */
                            &cReturned, &cTotal, &cbNeeded,
                            NULL) ;

   /* Only continue if the error codes ERROR_MORE_DATA or       */
   /* NERR_BufTooSmall are returned.                               */
   if (splerr == ERROR_MORE_DATA || splerr == NERR_BufTooSmall)
   {
      /* Allocate memory for the buffer that will hold the returning info. */
      if (!DosAllocMem( &pBuf, cbNeeded,
                        PAG_READ|PAG_WRITE|PAG_COMMIT) )
      {
         cbBuf = cbNeeded ;

         /* Make call again with the proper buffer size.                   */
         splerr = SplEnumDevice(pszComputerName, ulLevel, pBuf, cbBuf,
                                &cReturned, &cTotal,
                                &cbNeeded, NULL) ;

         /* If no errors, print out the buffer information.                */
         if (splerr == NO_ERROR)
         {
            for (i=0;i < cReturned ; i++)
            {
               /* Each time through the loop increase the pointer.         */
               pprd3 = (PPRDINFO3)pBuf+i ;
               printf("Device info:pszPrinterName   - %s\n",
                            pprd3->pszPrinterName) ;
               printf("  pszUserName - %s\n", pprd3->pszUserName);
               printf("  pszLogAddr  - %s\n", pprd3->pszLogAddr);
               printf("  uJobId      - %d  fsStatus - %X\n",
                            pprd3->uJobId ,  pprd3->fsStatus);
               printf("  pszStatus   - %s\n", pprd3->pszStatus);
               printf("  pszComment  - %s\n", pprd3->pszComment);
               printf("  pszDrivers  - %s\n", pprd3->pszDrivers);
               printf("  time        - %d usTimeOut - %X\n",
                            pprd3->time ,  pprd3->usTimeOut);
             }
         }
         DosFreeMem(pBuf) ;
      }
   } /* end if  */
   else
   {
       printf("SplEnumDevice splerr=%ld, cTotal=%ld, cReturned=%ld, cbNeeded=%ld\n",
              splerr, cTotal, cReturned, cbNeeded) ;
   }
   DosExit( EXIT_PROCESS , 0 ) ;
   return(splerr);
}   /* end main */


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