Highlighted
Contributor.
Contributor.
70 views

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

Jump to solution

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.

 

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

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

View solution in original post

2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

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

View solution in original post

Highlighted
Micro Focus Expert
Micro Focus Expert

@rjrjack 

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

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.