Write Text Directly to Printer


The DirectPrint function in the following class accepts a character string for a network or
local printer, and then prints Capt. Crunch to the printer.

This class is very simplified so that I can separate the minimum steps required to
send text to the printer from all of the stuff that makes printing really work.

To download the class and supporting MS Visaul C++ files, click TextOut.zip

To e-mail a suggestion or comment, write to sam@gilcrist.com
/*****************************************************************************
* Author : R. Sam Gilcrist
* Date : 20 Mar 2003
* Purpose : Very simple class to write text to a printer
* Acknowledgement
* Much of DirectPrint comes from *****************************************************************************/


#include "stdafx.h"
#include "TextOut.h"
#include "PrintFunc.h"
#include "windows.h"
#include "string.h"
#include "fcntl.h"
#include "winspool.h"

//Constructor and Destructor

PrintFunc::PrintFunc()
{

}

PrintFunc::~PrintFunc()
{

}

/***************************************************************************
* printer : the name of the printer we are going to use
* jobname : name of print job. this will appear in status screen
*****************************************************************************/

bool PrintFunc::DirectPrint(char *printer, char *jobname)
{
HANDLE hprt;
DOC_INFO_1 di1;
DWORD bsent; // number of bytes written - value returned from WritePrinter
DWORD job;


char MyText[125] = {"Capt. Crunch\0"}; //text to be printed on page

if(OpenPrinter(printer,&hprt,NULL))
{ }
else return true;
}