Skip to main content
Dominique Sacre
Rocketeer
Sep 10, 2020 8:55 AM UTC

I have to call "PC_PRINTER_REDIRECTION_PROC" or printer doesn't print.

Below are the relevant parts of a program for printing to my PC printer. I am running Windows 10 and Visual Studio. The program prints the "howdy" line, but if don't call  "PC_PRINTER_REDIRECTION_PROC"  the printer does not print "howdy"

I thought the main purpose of the "PC_PRINTER_REDIRECTION_PROC" call was so you could get the printer handle and do things like set the font - have not seen anything saying that you have to do the call. What am I missing?

I can comment out the call to set the font in "SetFont" and it still prints.

------------------------------------------------------------------------------

    Select PrintFile assign to printer
            organization is line sequential
            file status is file-status.

    FD PrintFile.
    01 PrintRec pic x(80).

     set user-func to entry "SetFont".

     call "PC_PRINTER_REDIRECTION_PROC"
            using by value flags
            user-func
           end-call.

    open output PrintFile.

    move 'howdy' to PrintRec.
    write PrintRec after advancing 0 lines.
    close PrintFile.

entry "SetFont" using by value printer-handle.
                call "PC_PRINTER_SET_FONT"
                    using printer-handle
                                   font-family-name
                                   by value font-size
                                   by value font-style
                     returning status-code
                 end-call.
    exit program returning status-code.

 

 

    2 replies

    Gael Wilson
    Rocketeer
    Sep 10, 2020 1:27 PM UTC

    Below are the relevant parts of a program for printing to my PC printer. I am running Windows 10 and Visual Studio. The program prints the "howdy" line, but if don't call  "PC_PRINTER_REDIRECTION_PROC"  the printer does not print "howdy"

    I thought the main purpose of the "PC_PRINTER_REDIRECTION_PROC" call was so you could get the printer handle and do things like set the font - have not seen anything saying that you have to do the call. What am I missing?

    I can comment out the call to set the font in "SetFont" and it still prints.

    ------------------------------------------------------------------------------

        Select PrintFile assign to printer
                organization is line sequential
                file status is file-status.

        FD PrintFile.
        01 PrintRec pic x(80).

         set user-func to entry "SetFont".

         call "PC_PRINTER_REDIRECTION_PROC"
                using by value flags
                user-func
               end-call.

        open output PrintFile.

        move 'howdy' to PrintRec.
        write PrintRec after advancing 0 lines.
        close PrintFile.

    entry "SetFont" using by value printer-handle.
                    call "PC_PRINTER_SET_FONT"
                        using printer-handle
                                       font-family-name
                                       by value font-size
                                       by value font-style
                         returning status-code
                     end-call.
        exit program returning status-code.

     

     

    Hi,

    By default,  when you write to a file using 'assign to printer' the COBOL run-time system will attempt to write to the LPT1 device. If you don't have a printer assigned to LPT1 nothing will be written, which sounds like what you are describing.

    When PC_PRINTER_REDIRECTION_PROC is used the writes are redirected to the default printer via the Windows print spooler service rather than being written directly to a device.

    I hope that helps.

    Gael

    Gael Wilson
    Rocketeer
    Sep 11, 2020 12:56 PM UTC

    Hi,

    By default,  when you write to a file using 'assign to printer' the COBOL run-time system will attempt to write to the LPT1 device. If you don't have a printer assigned to LPT1 nothing will be written, which sounds like what you are describing.

    When PC_PRINTER_REDIRECTION_PROC is used the writes are redirected to the default printer via the Windows print spooler service rather than being written directly to a device.

    I hope that helps.

    Gael

     

    I forgot to mention in my previous reply that it is not necessary to call PC_PRINTER_REDIRECTION_PROC in order to write via the print spooler. You can set a run-time tunable to enable that behaviour, so you can do so without having to modify your source code. See :

    General Reference -> Run-time System Configuration -> Run-time Tunables -> List of Run-time Tunables -> printer_redirection in

    the product documentation for details.

    Gael