Thread: Printers and Portability

  1. #1
    Master of Puppets rwmarsh's Avatar
    Join Date
    Feb 2006

    Printers and Portability

    I was wondering if there was a good portable way to send information to a printer? Using fstreams will not work with my setup (windows xp and an ink jet printer) and the only other way I know of is with windows api's which (correct me if I am wrong) will only work on a windows OS.

    I have been playing with pdCurses and I like it so far. I would like to start using it on a regular basis but I have not seen anything on printer functions for it and I would hate to have to #include <windows.h> just so that I can send text to the printer.
    Using DEV-C++ Under Windows XP

    "No! Do, or Do Not. There is no Try..."

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Assuming you have a printer connected to the LPT1 port, you create an ofstream object and open lpt1.
    ofstream printer("lpt1");
    EDIT: Oh... you said portable... I'm not sure if lpt1 is recognized as a printer port under other systems. Most probably not.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > I was wondering if there was a good portable way to send information to a printer?
    There is no standard device name for a printer, nor is there a standard way of finding out if you've even got a printer.
    Not to mention the vast variety of printers and printer languages (PCL, Postscript, ... )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Try one of the cross-platform UI frameworks like Qt, GTK+ or wxWidgets. They ought to provide printing.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    FYI - Some printers have a special secret protocol that requires you to use the Windows driver (and WinAPI). I have a cheap Canon ink jet, and it doesn't respond if you simply it send ASCII. It won't work with DOS applications at all.

Popular pages Recent additions subscribe to a feed