Thread: c++ addressing the centronics printerport

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    21

    c++ addressing the centronics printerport

    Hi,
    I`m using the following code:

    freopen("RPN","w",stdout);

    or:

    #include<fstream.h>
    void main()
    {
    ofstream lst("PRN");
    lst<<"print this";

    }

    This works fine on the Borlandc Dos version,
    but neither works on the BC5 windows compiler,
    nor does it make the printer come online on the CBuilder though it does compile fine on all.

    I guess there`s a linker setting or so.

    Anybody knows any help?
    I`d appreciate.

    Johannes

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Your not using DOS anymore. Get a handle to the port with the CreateFile() Win32 API routine then use handle based I/O routines. You can then write to and read from the parallel port.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719
    inp
    outp
    "What are you after - the vague post of the week award?" - Salem
    IPv6 Ready.
    Travel the world, meet interesting people...kill them.
    Trying to fix or change something, only guaruntees and perpetuates its existence.
    I don't know about angels, but it is fear that gives men wings.
    The problem with wanting something is the fear of losing it, or never having it. The thought makes you weak.

    E-Mail Xei

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Instead of bolding your text, please put code tags. [ code] instead of [ b] (no space of course). Next, don't use void main(), use int main(). Then use the new headers:
    Code:
    #include <fstream>
    using namespace std;

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    21

    c++ addressing printer

    Hi,
    [code]
    #include <fstream>
    using namespace std; [/code ]

    Can anyone give me the entire code to get the printer to work on the cbuilder?
    I`m not familiar with namespace.

    this always used to work , but doesn`t with the builder:
    [code]
    #include<fstream.h>
    void main()
    {
    ofstream lst("PRN");
    lst<<"print this";
    [/code ]

    I also got a hint to use
    Code:
    outp
    but don`t know how.

    Also: Is there a button for the codetag?I only see buttons for bold ...

    Thanks ,

    Jpohannes

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You cannot use 16 bit DOS routines on a 32 bit Windows system. Windows will, (basically), not let you access ports directly. It is a multi-tasking OS.

    Suppose the system was in the middle of a 5000 page print out when your program pops up a sticks "print this" part way through page 4000?

    You can either use the method I said before, or write a device driver. Hint, one is easier than the other. If you want to program Windows systems, forget 16 bit stuff, it's legacy, it's gone.

    I don't think there are buttons. use [code] at the start and [/code] at the end.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d array addressing
    By R.Stiltskin in forum C++ Programming
    Replies: 6
    Last Post: 08-19-2008, 01:36 AM
  2. memory addressing
    By sarathius in forum C Programming
    Replies: 7
    Last Post: 03-31-2008, 08:23 AM
  3. ipv6 addressing
    By venkatam in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2008, 06:52 AM
  4. Indirect Addressing uses how many bits?
    By franziss in forum C Programming
    Replies: 8
    Last Post: 12-16-2004, 04:33 PM
  5. addressing hardware ports using c++
    By juhigarg in forum C++ Programming
    Replies: 3
    Last Post: 10-23-2001, 12:33 PM