Ignore:
Timestamp:
Apr 5, 2013, 5:29:49 AM (12 years ago)
Author:
Alex Taylor
Message:

Added RPUPrinterDelete function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rxprtutl/trunk/rxprtutl.c

    r6 r7  
    104104    "RPUPortSet",
    105105    "RPUPrinterCreate",
     106    "RPUPrinterDelete",
    106107    "RPUPrinterQuery",
    107108    "RPUVersion"
     
    124125RexxFunctionHandler RPUPortSet;
    125126RexxFunctionHandler RPUPrinterCreate;
     127RexxFunctionHandler RPUPrinterDelete;
    126128RexxFunctionHandler RPUPrinterQuery;
    127129RexxFunctionHandler RPUQueueDefault;
     
    10151017 * been installed already.                                                   *
    10161018 *                                                                           *
    1017  * The WPS object is created with default settings, other than those which   *
    1018  * are specified here.                                                       *
    1019  *                                                                           *
    1020  * This function will not create a LAN printer object.  Use the function     *
    1021  * RPUPrinterCreateRemote (not yet implemented) for that purpose.            *
     1019 * The WPS object is created with default settings (other than those which   *
     1020 * are specified here).  It will be assigned an object-ID automatically.     *
     1021 *                                                                           *
     1022 * This function will not create a remote (LAN) printer object.              *
    10221023 *                                                                           *
    10231024 * REXX ARGUMENTS:                                                           *
     
    10271028 *   4. The default printer driver.model to be associated with               *
    10281029 *      the device.  If specified, this must be installed in the             *
    1029  *      system already.  If NOT specified, IBMNULL will be assumed           *
    1030  *      if the specified printer device does not already exist.   (OPTIONAL) *
     1030 *      system already.  If not specified, and the named printer             *
     1031 *      device does not already exist, IBMNULL will be assumed.   (OPTIONAL) *
    10311032 *   5. The printer object title (i.e. human-readable name).  If             *
    10321033 *      not specified, the physical name will be used.            (OPTIONAL) *
     
    10461047              pszModel      = NULL,
    10471048              pszTitle      = NULL;
    1048 //            pszOID        = NULL;
    1049 //  CHAR      szSetup[ US_SS_MAXZ ] = {0};
    10501049    SPLERR    rc;
    10511050
     
    10621061    if (( argc > 4 ) && ( ! RXVALIDSTRING( argv[4] )))
    10631062        return ( 40 );
    1064 //  if (( argc > 5 ) && ( ! RXVALIDSTRING( argv[5] )))
    1065 //      return ( 40 );
    10661063
    10671064    pszQueueName  = argv[0].strptr;
     
    10701067    if ( argc > 3 ) pszModel = argv[3].strptr;
    10711068    pszTitle = ( argc > 4 ) ? argv[4].strptr : pszDeviceName;
    1072 //  if ( argc > 5 ) pszOID = argv[5].strptr;
    10731069
    10741070    // Find out if device exists already
     
    10781074        // Nope, create it now
    10791075        devinfo.pszPrinterName = pszDeviceName;
    1080         devinfo.pszUserName = NULL;
    1081         devinfo.pszLogAddr  = pszPortName;
    1082         devinfo.pszComment  = pszTitle;
    1083         devinfo.pszDrivers  = pszModel ? pszModel : "IBMNULL";
    1084         devinfo.usTimeOut   = 45;
     1076        devinfo.pszUserName    = NULL;
     1077        devinfo.pszLogAddr     = pszPortName;
     1078        devinfo.pszComment     = pszTitle;
     1079        devinfo.pszDrivers     = pszModel ? pszModel : "IBMNULL";
     1080        devinfo.usTimeOut      = 45;
    10851081        rc = SplCreateDevice( NULL, 3, &devinfo, sizeof( devinfo ));
    10861082        if ( rc != NO_ERROR ) {
     
    11021098
    11031099        // Nope, create it now
    1104         qinfo.pszName = pszQueueName;
    1105         qinfo.uPriority = PRQ_DEF_PRIORITY;
    1106         qinfo.fsType = PRQ3_TYPE_RAW;
    1107         qinfo.pszPrProc = "PMPRINT";
    1108         qinfo.pszComment = pszTitle;
    1109         qinfo.pszPrinters = pszDeviceName;
     1100        qinfo.pszName       = pszQueueName;
     1101        qinfo.uPriority     = PRQ_DEF_PRIORITY;
     1102        qinfo.fsType        = PRQ3_TYPE_RAW;
     1103        qinfo.pszPrProc     = "PMPRINT";
     1104        qinfo.pszComment    = pszTitle;
     1105        qinfo.pszPrinters   = pszDeviceName;
    11101106        qinfo.pszDriverName = pszModel ? pszModel : "IBMNULL";
    1111         //qinfo.pDriverData = NULL;
    11121107        rc = SplCreateQueue( NULL, 3, &qinfo, sizeof( qinfo ));
    11131108        if ( rc != NO_ERROR ) {
    11141109            WriteErrorCode( rc, "SplCreateQueue");
    11151110            MAKERXSTRING( *prsResult, "0", 1 );
    1116             if ( fNewD );   // TODO delete device
     1111            if ( fNewD ) SplDeleteDevice( NULL, pszDeviceName );
    11171112            return ( 0 );
    11181113        }
     
    11211116        WriteErrorCode( rc, "SplQueryQueue");
    11221117        MAKERXSTRING( *prsResult, "0", 1 );
    1123         if ( fNewD );   // TODO delete device
     1118        if ( fNewD ) SplDeleteDevice( NULL, pszDeviceName );
    11241119        return ( 0 );
    11251120    }
    11261121
    1127 /* Actually, this doesn't seem to be necessary...
    1128 
    1129     sprintf( szSetup, "QUEUENAME=%s;TAKEDEFAULTS=YES;", pszQueueName);        // TODO verify length
    1130     if ( pszOID ) {
    1131         strncat( szSetup, "OBJECTID=", US_SS_MAXZ-1 );
    1132         strncat( szSetup, pszOID, US_SS_MAXZ-1 );
    1133         strncat( szSetup, ";", US_SS_MAXZ-1 );
    1134     }
    1135     if ( WinCreateObject("WPPrinter", pszTitle, szSetup,
    1136                          "<WP_DESKTOP>", CO_FAILIFEXISTS ) == NULLHANDLE )
    1137     {
    1138         WriteErrorCode( 0, "WinCreateObject");
    1139         MAKERXSTRING( *prsResult, "0", 1 );
    1140         if ( fNewD );   // TODO delete device
    1141         if ( fNewQ );   // TODO delete queue
     1122    MAKERXSTRING( *prsResult, "1", 1 );
     1123    return ( 0 );
     1124}
     1125
     1126
     1127/* ------------------------------------------------------------------------- *
     1128 * RPUPrinterDelete                                                          *
     1129 *                                                                           *
     1130 * Deletes a local printer queue and its associated print device definition. *
     1131 *                                                                           *
     1132 * REXX ARGUMENTS:                                                           *
     1133 *   1. The name of the printer queue to be deleted.              (REQUIRED) *
     1134 *                                                                           *
     1135 * REXX RETURN VALUE:                                                        *
     1136 *   1 on success, or 0 if an error occurred.  (1 will be returned even if   *
     1137 *   the WPS printer object could not be deleted, so long as the queue and   *
     1138 *   device were dstroyed successfully.)                                     *
     1139 * ------------------------------------------------------------------------- */
     1140ULONG APIENTRY RPUPrinterDelete( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     1141{
     1142    PPRQINFO3 pInfo         = NULL;
     1143    ULONG     cbBuf         = 0;
     1144    PSZ       pszQueueName  = NULL,
     1145              pszDeviceName = NULL;
     1146    HOBJECT   hObj;
     1147    SPLERR    rc;
     1148
     1149
     1150    // Reset the error indicator
     1151    WriteErrorCode( 0, NULL );
     1152
     1153    // Validate the REXX arguments
     1154    if (( argc != 1 ) || ( ! RXVALIDSTRING( argv[0] )))
     1155        return ( 40 );
     1156
     1157    pszQueueName = argv[0].strptr;
     1158    hObj = PrinterObjectHandle( pszQueueName );
     1159
     1160    rc = SplQueryQueue( NULL, pszQueueName, 3, NULL, 0, &cbBuf );
     1161    if (( rc != NO_ERROR ) && ( rc != NERR_BufTooSmall )) {
     1162        WriteErrorCode( rc, "SplQueryQueue");
     1163        MAKERXSTRING( *prsResult, "0", 1 );
    11421164        return ( 0 );
    11431165    }
    1144 */
     1166    pInfo = (PPRQINFO3) malloc( cbBuf );
     1167    if ( !pInfo ) {
     1168        WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc");
     1169        MAKERXSTRING( *prsResult, "0", 1 );
     1170        return ( 0 );
     1171    }
     1172    rc = SplQueryQueue( NULL, pszQueueName, 3, pInfo, cbBuf, &cbBuf );
     1173    if ( rc != NO_ERROR ) {
     1174        WriteErrorCode( rc, "SplQueryQueue");
     1175        MAKERXSTRING( *prsResult, "0", 1 );
     1176        goto cleanup;
     1177    }
     1178    pszDeviceName = strtok( pInfo->pszPrinters, ",");
     1179    rc = SplDeleteDevice( NULL, pszDeviceName );
     1180    if ( rc != NO_ERROR ) {
     1181        WriteErrorCode( rc, "SplDeleteDevice");
     1182        MAKERXSTRING( *prsResult, "0", 1 );
     1183        goto cleanup;
     1184    }
     1185
     1186    // Try and destroy the WPS object
     1187    if ( hObj != NULLHANDLE ) WinDestroyObject( hObj );
     1188
     1189    MAKERXSTRING( *prsResult, "1", 1 );
     1190cleanup:
     1191    free( pInfo );
    11451192    return ( 0 );
    11461193}
Note: See TracChangeset for help on using the changeset viewer.