Posted on 1999-07-11
Medium Priority
Last Modified: 2010-04-15
how to call a printer in c ?
Question by:eddyhalim
LVL 10

Expert Comment

ID: 1263504
Which OS? What to you mean with "call"?

Expert Comment

ID: 1263505
If you are using dos - and if I remember right unix is nearly the same - there is a already opened stream named stdprn.
so you can print like writing to a file:
this works fine for simple text.
If you have to print something other than simple text and you have a OS without printer support you have to know the printer control commands (for example for switching from text to grapic mode) the control commands may be different for each printer type. These comands must be send to the printer before (for init) you start to print and often also while you print (print mode changing, print position,...)

If you have an OS that supports printing - like Windows - things are much easier:
Drivers for the supported printers are already installed.
You print like you would draw on the screen regardless what kind of printer is used.


Accepted Solution

Triskelion earned 20 total points
ID: 1263506
You can also use fopen if it is LPT1, LPT2 or any other printing device.

   FILE * hPrinter;
   hPrinter=fopen("LPT1", "wb");

Author Comment

ID: 1263507
how aboout in graphic mode?please list the source for me?

Expert Comment

ID: 1263508
You should!!!! tell wich operating system
DOS: Hard, no OS support, you have to do it for each printer type by yourself.
Select all the printers you want to support.
Buy them to test your printer output.
Read the command table of each printer.
select the commands you need for your printings.
build the output(mix between printer command and data to print)
and at last
printIt(char* WhatYouHaveToPint,long SizeOfWhatYouHaveToPint)
   FILE * hPrinter;
   hPrinter=fopen("LPT1", "wb");
Windows: Much easier
PrintIt(HDC PrinterDeviceContect)
If it works for one printer it should work for all printers windows has device drivers installed.

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question