How do you print directly under windows 7 platform using Visual Studio 2010 COBOL and USB PRINTER?

[Migrated content. Thread originally posted on 28 March 2012]

I need to be able to print directly to a printer so that a test page can be sent out and redone until the print is aligned. This works under Micro Focus COBOL (Unix) by the file-id being '/dev/lp1' or /dev/lp0/ where these were parallel printers but now we are moving to Windows 7 and all of the new printers are USB. There is also a restart in the program so that all of the pages printed correctly do not have to be reprinted.

  • Verified Answer

    There are a couple ways to do this under Windows.

    Do the following:

    1. Create a textfile called cobconfig.cfg and add the following line to it:

    set printer_redirection=TRUE

    2. set the environment variable COBCONFIG=c:\myfolder\cobconfig.cfg replacing c:\myfolder\ with the actual location of cobconfig.cfg on your system.

    3. In your program code the printer file as:

    select print-file assign to printer
    organization is line sequential.

    4. Now when the file is open all output will be redirected to the print spooler for your default printer.

    5. If you need to change the default printer for your program then you should call the library routine PC_PRINTER_SET_DEFAULT.

    See the entire list of Printer library routines in the documentation:

    Another alternative is to write the file to disk and then send it to the printer using PC_PRINT_FILE.

    Thanks.