Skip to main content

Printer tray names

  • August 15, 2014
  • 3 replies
  • 2 views

Andreas Weinand
Forum|alt.badge.img+2

We want to show the possible printer tray names and try to use DeviceCapabilities from winspool.drv.

If I enter the  debugger and step over the DeviceCapabilities-call it works perfectly - again and again as long as I stay in the program.

If the call is executed without entering the debugger I get a "memory access violation".

Here is the code:

       01            WK-WINSPOOLDRVJN  PIC X(01).

       01            WK-TRAYTABELLE.
           02        WK-TRAYSATZ       OCCURS MAX-PAPER-TRAYS.
            03       WK-TRAYNAME       PIC X(24).

       01            WINSPOOL-PRINTER  PIC X(80).
       01            WINSPOOL-PORT     PIC X(80).
       01            WINSPOOL-FC       PIC 9(4) COMP-5.

=================================================================       
           MOVE "J"                    TO WK-WINSPOOLDRVJN.

           CALL "c:\\Windows\\System32\\winspool.drv"
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           MOVE WRAL50-COMBOZEILE      TO WINSPOOL-PRINTER.
           INSPECT WINSPOOL-PRINTER    REPLACING TRAILING SPACES
                                       BY X"00".

           MOVE WINPRINT-PORT          TO WINSPOOL-PORT.
           INSPECT WINSPOOL-PORT       REPLACING TRAILING SPACES
                                       BY X"00".
                                       
           MOVE SPACE                  TO WK-TRAYTABELLE.
           MOVE 12                     TO WINSPOOL-FC.

           CALL "DeviceCapabilitiesA"  USING
                BY REFERENCE  WINSPOOL-PRINTER
                BY REFERENCE  WINSPOOL-PORT
                BY VALUE      WINSPOOL-FC
                BY REFERENCE  WK-TRAYTABELLE
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           IF   WK-TRAYTABELLE         = SPACE
                MOVE "N"               TO WK-WINSPOOLDRVJN.

Do you see my error or do you have a tip for me ?

              
Thanks in advance for your support.

Andreas

3 replies

Stephen Hjerpe
  • Participating Frequently
  • August 15, 2014

We want to show the possible printer tray names and try to use DeviceCapabilities from winspool.drv.

If I enter the  debugger and step over the DeviceCapabilities-call it works perfectly - again and again as long as I stay in the program.

If the call is executed without entering the debugger I get a "memory access violation".

Here is the code:

       01            WK-WINSPOOLDRVJN  PIC X(01).

       01            WK-TRAYTABELLE.
           02        WK-TRAYSATZ       OCCURS MAX-PAPER-TRAYS.
            03       WK-TRAYNAME       PIC X(24).

       01            WINSPOOL-PRINTER  PIC X(80).
       01            WINSPOOL-PORT     PIC X(80).
       01            WINSPOOL-FC       PIC 9(4) COMP-5.

=================================================================       
           MOVE "J"                    TO WK-WINSPOOLDRVJN.

           CALL "c:\\Windows\\System32\\winspool.drv"
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           MOVE WRAL50-COMBOZEILE      TO WINSPOOL-PRINTER.
           INSPECT WINSPOOL-PRINTER    REPLACING TRAILING SPACES
                                       BY X"00".

           MOVE WINPRINT-PORT          TO WINSPOOL-PORT.
           INSPECT WINSPOOL-PORT       REPLACING TRAILING SPACES
                                       BY X"00".
                                       
           MOVE SPACE                  TO WK-TRAYTABELLE.
           MOVE 12                     TO WINSPOOL-FC.

           CALL "DeviceCapabilitiesA"  USING
                BY REFERENCE  WINSPOOL-PRINTER
                BY REFERENCE  WINSPOOL-PORT
                BY VALUE      WINSPOOL-FC
                BY REFERENCE  WK-TRAYTABELLE
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           IF   WK-TRAYTABELLE         = SPACE
                MOVE "N"               TO WK-WINSPOOLDRVJN.

Do you see my error or do you have a tip for me ?

              
Thanks in advance for your support.

Andreas

Have you seen our prndemox.cbl example? the source-lines in PRNDEMOX.cbl use WINPRINT-GET-PRINTER-MEDIA to search for the paper-trays.


We want to show the possible printer tray names and try to use DeviceCapabilities from winspool.drv.

If I enter the  debugger and step over the DeviceCapabilities-call it works perfectly - again and again as long as I stay in the program.

If the call is executed without entering the debugger I get a "memory access violation".

Here is the code:

       01            WK-WINSPOOLDRVJN  PIC X(01).

       01            WK-TRAYTABELLE.
           02        WK-TRAYSATZ       OCCURS MAX-PAPER-TRAYS.
            03       WK-TRAYNAME       PIC X(24).

       01            WINSPOOL-PRINTER  PIC X(80).
       01            WINSPOOL-PORT     PIC X(80).
       01            WINSPOOL-FC       PIC 9(4) COMP-5.

=================================================================       
           MOVE "J"                    TO WK-WINSPOOLDRVJN.

           CALL "c:\\Windows\\System32\\winspool.drv"
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           MOVE WRAL50-COMBOZEILE      TO WINSPOOL-PRINTER.
           INSPECT WINSPOOL-PRINTER    REPLACING TRAILING SPACES
                                       BY X"00".

           MOVE WINPRINT-PORT          TO WINSPOOL-PORT.
           INSPECT WINSPOOL-PORT       REPLACING TRAILING SPACES
                                       BY X"00".
                                       
           MOVE SPACE                  TO WK-TRAYTABELLE.
           MOVE 12                     TO WINSPOOL-FC.

           CALL "DeviceCapabilitiesA"  USING
                BY REFERENCE  WINSPOOL-PRINTER
                BY REFERENCE  WINSPOOL-PORT
                BY VALUE      WINSPOOL-FC
                BY REFERENCE  WK-TRAYTABELLE
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           IF   WK-TRAYTABELLE         = SPACE
                MOVE "N"               TO WK-WINSPOOLDRVJN.

Do you see my error or do you have a tip for me ?

              
Thanks in advance for your support.

Andreas

How do you have MAX-PAPER-TRAYS defined, and what is the value? I tried your code and it worked well, but if I set MAX-PAPER-TRAYS to a number lower than the actual number of trays defined, the call to "DeviceCapabilitiesA" caused some memory corruption. I presume this is because this makes the WK-TRAYTABELLE table too small, so DeviceCapabilitesA attempts to write too much data to it and causes an overflow.


Andreas Weinand
Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • August 18, 2014

We want to show the possible printer tray names and try to use DeviceCapabilities from winspool.drv.

If I enter the  debugger and step over the DeviceCapabilities-call it works perfectly - again and again as long as I stay in the program.

If the call is executed without entering the debugger I get a "memory access violation".

Here is the code:

       01            WK-WINSPOOLDRVJN  PIC X(01).

       01            WK-TRAYTABELLE.
           02        WK-TRAYSATZ       OCCURS MAX-PAPER-TRAYS.
            03       WK-TRAYNAME       PIC X(24).

       01            WINSPOOL-PRINTER  PIC X(80).
       01            WINSPOOL-PORT     PIC X(80).
       01            WINSPOOL-FC       PIC 9(4) COMP-5.

=================================================================       
           MOVE "J"                    TO WK-WINSPOOLDRVJN.

           CALL "c:\\Windows\\System32\\winspool.drv"
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           MOVE WRAL50-COMBOZEILE      TO WINSPOOL-PRINTER.
           INSPECT WINSPOOL-PRINTER    REPLACING TRAILING SPACES
                                       BY X"00".

           MOVE WINPRINT-PORT          TO WINSPOOL-PORT.
           INSPECT WINSPOOL-PORT       REPLACING TRAILING SPACES
                                       BY X"00".
                                       
           MOVE SPACE                  TO WK-TRAYTABELLE.
           MOVE 12                     TO WINSPOOL-FC.

           CALL "DeviceCapabilitiesA"  USING
                BY REFERENCE  WINSPOOL-PRINTER
                BY REFERENCE  WINSPOOL-PORT
                BY VALUE      WINSPOOL-FC
                BY REFERENCE  WK-TRAYTABELLE
           ON EXCEPTION
                MOVE "N"               TO WK-WINSPOOLDRVJN
                GO TO PCPDRU10MEDIA-WINPRINT
           END-CALL.

           IF   WK-TRAYTABELLE         = SPACE
                MOVE "N"               TO WK-WINSPOOLDRVJN.

Do you see my error or do you have a tip for me ?

              
Thanks in advance for your support.

Andreas

Hi Chuck,

thanks for your quick reply.

I tried to use MAX-PAPER-TRAYS from the copybook WINPRINT.DEF

WINPRINT.DEF:       78  MAX-PAPER-TRAYS                     VALUE 13.

Or what do you think could be a reasonable number ?