SplControlDevice - Example Code

This sample code demonstrates the result of various actions that can be performed on the print device by this function call. At the command line, a print device name is entered along with an action code.

#define INCL_SPL
#define INCL_SPLDOSPRINT
#define INCL_SPLERRORS
#include <os2.h>
#include <stdio.h>       /* for printf function */

INT main (argc, argv)
   INT argc;
   CHAR *argv[];
{
   SPLERR splerr ;
   ULONG  ulControl=0L ;
   PSZ    pszComputerName = NULL ;
   PSZ    pszPrintDeviceName ;

   /* Input a Print Device Name and an Action Code on the command line       */
   if (argc != 3)
   {
      printf("Syntax is:  qcontrol  PrintDeviceName  ActionCode \n");
      printf("Action codes are: D-Delete, P-Pause, C-Continue, R-Restart\n\n");
      DosExit( EXIT_PROCESS , 0 ) ;
   }

   /* Get the print device name from the first input parameter.              */
   pszPrintDeviceName = argv[1];

   /* Get the action code from the second input parameter.                   */
   switch (argv[2][0])
   {
      case 'D':
        ulControl = PRD_DELETE ;
        break;
      case 'P':
        ulControl = PRD_PAUSE ;
        break;
      case 'C':
        ulControl = PRD_CONT ;
        break;
      case 'R':
        ulControl = PRD_RESTART ;
        break;
      default:
        printf("Invalid code\n");
        DosExit( EXIT_PROCESS , 0 ) ;
   }
   /* Call the function with the parameters obtained from the command line.  */
   splerr = SplControlDevice(pszComputerName, pszPrintDeviceName, ulControl);

   /* If there is an error returned, print it.                               */
   if (splerr != 0L)
   {
      switch (splerr)
      {
         case  NERR_DestNotFound :
            printf("Destination does not exist.\n");
            break;
         case  NERR_DestIdle:
            printf("This print device is idle - can't do control ops. \n");
            break;
         default:
            printf("Errorcode = %ld\n",splerr);
         }
   } else {
         printf("The print job operation was performed.\n\n");
   }
   DosExit( EXIT_PROCESS , 0 ) ;
   return (splerr) ;
}


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